// File: /workspace/github_cpp_makefile_star2_O2/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
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x190(%rdi), %r14
movq %r14, 0x198(%rdi)
movq %r14, 0x190(%rdi)
andq $0x0, 0x1a0(%rdi)
leaq 0x4458(%rip), %rdi      # 0x140e8
pushq $0x20
popq %r9
movl $0x2fff0000, %esi       # imm = 0x2FFF0000
movl $0x2fff0000, %edx       # imm = 0x2FFF0000
movl $0x140, %ecx            # imm = 0x140
movl $0xf0, %r8d
callq 0x4050
movq %rax, (%rbx)
testq %rax, %rax
je 0xff09
movb $0x0, 0x1a8(%rbx)
movq %rax, %rdi
movl $0x140, %esi            # imm = 0x140
movl $0xf0, %edx
callq 0x4680
movabsq $0xf000000100, %rax     # imm = 0xF000000100
movq %rax, 0x178(%rbx)
movq (%rbx), %rdi
pushq $-0x1
popq %rsi
pushq $0x2
popq %rdx
callq 0x4030
movq %rax, 0x8(%rbx)
pushq $0x1
popq %rdx
movq %rax, %rdi
movl $0x16362004, %esi       # imm = 0x16362004
movl $0x100, %ecx            # imm = 0x100
movl $0xf0, %r8d
callq 0x4660
movq %rax, 0x18(%rbx)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x8
popq %rcx
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x10(%rbx)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x8
popq %rcx
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x20(%rbx)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x8
popq %rcx
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x28(%rbx)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x8
popq %rcx
xorl %edi, %edi
movl $0x100, %esi            # imm = 0x100
movl $0xf0, %edx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x38(%rbx)
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
pushq $0x8
popq %rcx
xorl %edi, %edi
movl $0x300, %esi            # imm = 0x300
movl $0x2d0, %edx            # imm = 0x2D0
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x44d0
movq %rax, 0x30(%rbx)
movq 0x8(%rbx), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x44f0
movq 0x8(%rbx), %rdi
callq 0x4360
movq 0x8(%rbx), %rdi
callq 0x4090
leaq 0x40(%rbx), %r15
leaq 0x43a1(%rip), %rax      # 0x141a8
xorl %ecx, %ecx
cmpq $0x4c, %rcx
je 0xfe3b
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
jmp 0xfe09
movl $0x100, %edi            # imm = 0x100
callq 0x4670
movq %rax, 0x170(%rbx)
pushq $0x4c
popq %rcx
movq %rax, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x41e0
movq 0x10(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41d0
movq 0x20(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41d0
movq 0x28(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41d0
movq 0x38(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41d0
movq 0x30(%rbx), %rdi
movq 0x170(%rbx), %rsi
callq 0x41d0
movq 0x10(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x4a
popq %rdx
callq 0x4430
movq 0x20(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x4a
popq %rdx
callq 0x4430
movq 0x28(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x4a
popq %rdx
callq 0x4430
movq 0x38(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x4a
popq %rdx
callq 0x4430
movq 0x30(%rbx), %rdi
pushq $0x1
popq %rsi
pushq $0x4a
popq %rdx
callq 0x4430
andw $0x0, 0x188(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq 0xb0a8(%rip), %rax      # 0x1afb8
movq (%rax), %r15
callq 0x42c0
leaq 0x41d1(%rip), %rsi      # 0x140f0
movq %r15, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4500
movb $0x1, 0x1a8(%rbx)
jmp 0xfeff
movq %rax, %rbx
movq %r14, %rdi
callq 0x106ae
movq %rbx, %rdi
callq 0x4640