// File: /workspace/github_cpp_makefile_star2_O3/khedoros[P]khednes/compositor.cpp
// Function: compositor::compositor(int)
compositor::compositor(int res) {
    /* Initialize the SDL library */
    screen = SDL_CreateWindow("KhedNES",
                              SDL_WINDOWPOS_CENTERED,
                              SDL_WINDOWPOS_CENTERED,
                              320, 240,
                              SDL_WINDOW_RESIZABLE);
    if ( screen == NULL ) {
        fprintf(stderr, "Couldn't set 320x240x8 video mode: %s\nStarting without video output.\n",
                SDL_GetError());
        //exit(1);
        dummy = true;
        return;
    }

    dummy = false;

    SDL_SetWindowMinimumSize(screen, 320, 240);
    cur_x_res=256;
    cur_y_res=240;

    render = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED/*|SDL_RENDERER_PRESENTVSYNC*/);
    //render = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED|SDL_RENDERER_PRESENTVSYNC);
    //render = SDL_CreateRenderer(screen, -1, SDL_RENDERER_SOFTWARE|SDL_RENDERER_PRESENTVSYNC);
    //render = SDL_CreateRenderer(screen, -1, SDL_RENDERER_SOFTWARE/*|SDL_RENDERER_PRESENTVSYNC*/);
    texture = SDL_CreateTexture(render, SDL_PIXELFORMAT_ARGB8888,SDL_TEXTUREACCESS_STREAMING,256,240);

    buffer = SDL_CreateRGBSurface(0,256,240,8,0,0,0,0);
    overlay = SDL_CreateRGBSurface(0,256,240,8,0,0,0,0);
    lps = SDL_CreateRGBSurface(0,256,240,8,0,0,0,0);
    hps = SDL_CreateRGBSurface(0,256,240,8,0,0,0,0);
    nt = SDL_CreateRGBSurface(0,768,720,8,0,0,0,0);

    SDL_SetRenderDrawColor(render, 0, 0, 0, 0);
    SDL_RenderClear(render);
    SDL_RenderPresent(render);

    for(int i=0;i<76;++i) {
        tv_palette[i].r=palette_table[i*3];
        tv_palette[i].g=palette_table[i*3+1];
        tv_palette[i].b=palette_table[i*3+2];
        if(i==NES_TRANSPARENT)
            tv_palette[i].a = 0;
        else
            tv_palette[i].a=255;
    }

    palstruct = SDL_AllocPalette(256);
    SDL_SetPaletteColors(palstruct,&tv_palette[0],0,76);

    SDL_SetSurfacePalette(buffer, palstruct);
    SDL_SetSurfacePalette(overlay, palstruct);
    SDL_SetSurfacePalette(lps, palstruct);
    SDL_SetSurfacePalette(hps, palstruct);
    SDL_SetSurfacePalette(nt, palstruct);

    SDL_SetColorKey(buffer, SDL_TRUE, NES_TRANSPARENT);
    SDL_SetColorKey(overlay, SDL_TRUE, NES_TRANSPARENT);
    SDL_SetColorKey(lps, SDL_TRUE, NES_TRANSPARENT);
    SDL_SetColorKey(hps, SDL_TRUE, NES_TRANSPARENT);
    SDL_SetColorKey(nt, SDL_TRUE, NES_TRANSPARENT);

    tv=false; //start with table_view deactivated
    delay = false;

}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq %rdi, %rbx
leaq 0x190(%rdi), %r15
movq %r15, 0x198(%rdi)
movq %r15, 0x190(%rdi)
movq $0x0, 0x1a0(%rdi)
leaq 0x43f5(%rip), %rdi      # 0x16118
movl $0x2fff0000, %esi       # imm = 0x2FFF0000
movl $0x2fff0000, %edx       # imm = 0x2FFF0000
movl $0x140, %ecx            # imm = 0x140
movl $0xf0, %r8d
movl $0x20, %r9d
callq 0x4060
movq %rax, (%rbx)
testq %rax, %rax
je 0x11fc0
movb $0x0, 0x1a8(%rbx)
movq %rax, %rdi
movl $0x140, %esi            # imm = 0x140
movl $0xf0, %edx
callq 0x4660
movabsq $0xf000000100, %rax     # imm = 0xF000000100
movq %rax, 0x178(%rbx)
movq (%rbx), %rdi
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movl $0x2, %edx
callq 0x4040
movq %rax, 0x8(%rbx)
movq %rax, %rdi
movl $0x16362004, %esi       # imm = 0x16362004
movl $0x1, %edx
movl $0x100, %ecx            # imm = 0x100
movl $0xf0, %r8d
callq 0x4640
movq %rax, 0x18(%rbx)
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %r14
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x10(%rbx)
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %r14
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x20(%rbx)
xorl %r14d, %r14d
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %r14
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x28(%rbx)
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %r14
pushq %r14
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x38(%rbx)
xorl %eax, %eax
xorl %edi, %edi
movl $0x300, %esi            # imm = 0x300
movl $0x2d0, %edx            # imm = 0x2D0
movl $0x8, %ecx
xorl %r8d, %r8d
xorl %r9d, %r9d
pushq %rax
pushq %rax
callq 0x44e0
addq $0x10, %rsp
movq %rax, 0x30(%rbx)
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x4500
movq 0x8(%rbx), %rdi
callq 0x4370
movq 0x8(%rbx), %rdi
callq 0x40a0
leaq 0x40(%rbx), %r14
leaq 0x432b(%rip), %rax      # 0x161d8
xorl %ecx, %ecx
movb -0x8(%rax), %dl
movb -0x4(%rax), %sil
movb %dl, 0x40(%rbx,%rcx,4)
movb %sil, 0x41(%rbx,%rcx,4)
movb (%rax), %dl
movb %dl, 0x42(%rbx,%rcx,4)
cmpq $0x4a, %rcx
setne %dl
negb %dl
movb %dl, 0x43(%rbx,%rcx,4)
incq %rcx
addq $0xc, %rax
cmpq $0x4c, %rcx
jne 0x11eaf
movl $0x100, %edi            # imm = 0x100
callq 0x4650
movq %rax, 0x170(%rbx)
movq %rax, %rdi
movq %r14, %rsi
xorl %edx, %edx
movl $0x4c, %ecx
callq 0x41f0
movq 0x10(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41e0
movq 0x20(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41e0
movq 0x28(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41e0
movq 0x38(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41e0
movq 0x30(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41e0
movq 0x10(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movq 0x20(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movq 0x28(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movq 0x38(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movq 0x30(%rbx), %rdi
movl $0x1, %esi
movl $0x4a, %edx
callq 0x4460
movw $0x0, 0x188(%rbx)
popq %rbx
popq %r14
popq %r15
retq
movq 0x9ff1(%rip), %rax      # 0x1bfb8
movq (%rax), %r14
callq 0x42f0
leaq 0x414a(%rip), %rsi      # 0x16120
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4510
movb $0x1, 0x1a8(%rbx)
jmp 0x11fba
movq %rax, %rbx
movq (%r15), %rdi
cmpq %r15, %rdi
je 0x12007
movq (%rdi), %r14
callq 0x4380
movq %r14, %rdi
cmpq %r15, %r14
jne 0x11ff7
movq %rbx, %rdi
callq 0x4610
nop