// File: /workspace/github_cpp_makefile_star2_O3/klyushinmisha[P]GBEmu/./src/GameBoy.cpp
// Function: GameBoy::Run()
void GameBoy::Run()
{
    scale = 2;
    pixels = new Uint32[scale * scale * 160 * 144];
    SDL_Init(SDL_INIT_EVERYTHING);
    
    SDL_Window* w = SDL_CreateWindow("GBEmu", 100, 100, scale * 160, scale * 144, 0);

    SDL_Event e;
    ren = SDL_CreateRenderer(w, -1, SDL_RENDERER_ACCELERATED);

    texture = SDL_CreateTexture(ren,
        SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STATIC, scale * 160, scale * 144);

    bool isRunning = true;
    SDL_ShowWindow(w);
    while (isRunning)
    {
        if (Drawing())
            Manager();
        else
        {
            SDL_RenderClear(ren);
            SDL_RenderCopy(ren, texture, nullptr, nullptr);
            SDL_RenderPresent(ren);
            SDL_UpdateTexture(texture, nullptr, pixels, scale * 160 * sizeof(Uint32));
            SDL_PollEvent(&e);
            switch (e.type)
            {
                case SDL_QUIT:
                    isRunning = false;
                    break;
                case SDL_KEYDOWN:
                    KeyDown(e);
                    break;
                case SDL_KEYUP:
                    KeyUp();
                    break;
            }
        }
    }

    delete pixels;
    SDL_DestroyTexture(texture);
    SDL_DestroyRenderer(ren);
    SDL_DestroyWindow(w);
    SDL_Quit();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movl $0x2, 0x40(%rdi)
movl $0x5a000, %edi          # imm = 0x5A000
callq 0x2040
movq %rax, 0x38(%rbx)
movl $0xf231, %edi           # imm = 0xF231
callq 0x21c0
movl 0x40(%rbx), %eax
movl %eax, %ecx
shll $0x5, %ecx
leal (%rcx,%rcx,4), %ecx
shll $0x4, %eax
leal (%rax,%rax,8), %r8d
leaq 0x374c(%rip), %rdi      # 0x6020
movl $0x64, %esi
movl $0x64, %edx
xorl %r9d, %r9d
callq 0x2060
movq %rax, %r14
movq %rax, %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x2, %edx
callq 0x2050
movq %rax, 0x28(%rbx)
movl 0x40(%rbx), %edx
movl %edx, %ecx
shll $0x5, %ecx
leal (%rcx,%rcx,4), %ecx
shll $0x4, %edx
leal (%rdx,%rdx,8), %r8d
movq %rax, %rdi
movl $0x16362004, %esi       # imm = 0x16362004
xorl %edx, %edx
callq 0x2310
movq %rax, 0x30(%rbx)
movq %r14, %rdi
callq 0x2130
leaq -0x50(%rbp), %r15
movq 0x20(%rbx), %rdi
callq 0x5ae6
testb %al, %al
je 0x2948
movq 0x20(%rbx), %rdi
callq 0x5a62
jmp 0x2930
movq 0x28(%rbx), %rdi
callq 0x21e0
movq 0x28(%rbx), %rdi
movq 0x30(%rbx), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2210
movq 0x28(%rbx), %rdi
callq 0x2090
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rdx
movl 0x40(%rbx), %eax
shll $0x7, %eax
leal (%rax,%rax,4), %ecx
xorl %esi, %esi
callq 0x2180
movq %r15, %rdi
callq 0x2140
movl -0x50(%rbp), %eax
cmpl $0x300, %eax            # imm = 0x300
je 0x29c0
cmpl $0x301, %eax            # imm = 0x301
je 0x29a5
cmpl $0x100, %eax            # imm = 0x100
jne 0x2930
jmp 0x29f0
movq 0x48(%rbx), %rax
andb $-0x10, 0xff00(%rax)
movq 0x48(%rbx), %rax
orb $0xf, 0xff00(%rax)
jmp 0x2930
movq -0x20(%rbp), %rax
movq %rax, 0x30(%rsp)
movups -0x50(%rbp), %xmm0
movups -0x40(%rbp), %xmm1
movups -0x30(%rbp), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %rbx, %rdi
callq 0x2a44
jmp 0x2930
movq 0x38(%rbx), %rdi
movl $0x4, %esi
callq 0x2200
movq 0x30(%rbx), %rdi
callq 0x2160
movq 0x28(%rbx), %rdi
callq 0x20e0
movq %r14, %rdi
callq 0x2030
callq 0x2080
addq $0x78, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq