// File: /workspace/github_cpp_makefile_star2_O2/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 0x21d0
movl 0x40(%rbx), %eax
imull $0xa0, %eax, %ecx
imull $0x90, %eax, %r8d
leaq 0x37a2(%rip), %rdi      # 0x6020
pushq $0x64
popq %rdx
movl %edx, %esi
xorl %r9d, %r9d
callq 0x2060
movq %rax, %r14
pushq $-0x1
popq %rsi
pushq $0x2
popq %rdx
movq %rax, %rdi
callq 0x2050
movq %rax, 0x28(%rbx)
movl 0x40(%rbx), %edx
imull $0xa0, %edx, %ecx
imull $0x90, %edx, %r8d
movq %rax, %rdi
movl $0x16362004, %esi       # imm = 0x16362004
xorl %edx, %edx
callq 0x2330
movq %rax, 0x30(%rbx)
movq %r14, %rdi
callq 0x2140
leaq -0x50(%rbp), %r15
movq %rbx, %rdi
callq 0x29b0
testb %al, %al
je 0x28e5
movq %rbx, %rdi
callq 0x29be
jmp 0x28cf
movq 0x28(%rbx), %rdi
callq 0x21f0
movq 0x28(%rbx), %rdi
movq 0x30(%rbx), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x2230
movq 0x28(%rbx), %rdi
callq 0x2090
movq 0x30(%rbx), %rdi
movq 0x38(%rbx), %rdx
imull $0x280, 0x40(%rbx), %ecx # imm = 0x280
xorl %esi, %esi
callq 0x2190
movq %r15, %rdi
callq 0x2150
movl -0x50(%rbp), %eax
cmpl $0x300, %eax            # imm = 0x300
je 0x294a
cmpl $0x301, %eax            # imm = 0x301
je 0x2940
cmpl $0x100, %eax            # imm = 0x100
jne 0x28cf
jmp 0x297a
movq %rbx, %rdi
callq 0x2a60
jmp 0x28cf
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 0x29cc
jmp 0x28cf
movq 0x38(%rbx), %rdi
pushq $0x4
popq %rsi
callq 0x2220
movq 0x30(%rbx), %rdi
callq 0x2170
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