// File: /workspace/github_cpp_makefile_star2_O1/khedoros[P]khednes/ppu3.cpp
// Function: ppu::ppu(rom&, int)
ppu::ppu(rom& romi, int res) : cart(romi), screen(1), scroll_shifts(0), frame(0) {
    if(screen.dummy) {
        dummy = true;
    }
    else {
        dummy = false;
    }
    //cout<<"Start ppu constructor"<<endl;
    //cout<<"\tRes: "<<res<<endl;
    //cout<<"End ppu constructor"<<endl<<endl;
    s.cycles = 0;
    s.reads = 0;
    s.twok2_reads = 0;
    s.writes = 0;
    s.dmas = 0;
    s.reads_during_render = 0;
    s.writes_during_render = 0;
    frame = 0;
    cleared_vsync = false;
    late_vsync_clear = false;
    spr_overflow_cycle = -1;
    spr_hit0_cycle = -1;
    recalc_overflow = true;
    recalc_s0 = true;
    table_view = false;
    init_scroll_x = init_scroll_y = 0;
    cycles_per_frame = CLK_PER_LINE * LINE_PER_FRAME;

    set_mirror(cart.get_mode());

    for(int i=0; i < 0x20; ++i)
        pal[i] = &(palette[i]);
    pal[0x10] = &(palette[0]);
    pal[0x14] = &(palette[4]);
    pal[0x18] = &(palette[8]);
    pal[0x1C] = &(palette[0x0c]);

    //tile_cache[table#][tile#][pal#][hflip][vflip]
    //        SDL_Surface * tile_cache[2][256][8][2][2];
    for(int table = 0; table < 2; ++table) {
        for(int tile = 0; tile < 256; ++tile) {
            for(int palette = 0; palette < 8; ++palette) {
                for(int hflip = 0; hflip < 2; ++hflip) {
                    for(int vflip = 0; vflip < 2; ++vflip) {
                        tile_cache[table][tile][palette][hflip][vflip] = NULL;
                    }
                }
            }
        }
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq %rsi, (%rdi)
leaq 0x8(%rdi), %r14
movq %r14, %rdi
movl $0x1, %esi
callq 0x11e14
movq $0x0, 0x1d8(%rbx)
movl $0x0, 0x1e0(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x1b8(%rbx)
movups %xmm0, 0x1c4(%rbx)
leaq 0x1f0(%rbx), %r15
leaq 0x7(%rsp), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xfd24
leaq 0x1b8(%rbx), %rax
movl $0x0, 0x2185c(%rbx)
movb 0x1b0(%rbx), %cl
movb %cl, 0x21861(%rbx)
xorl %ecx, %ecx
movq %rcx, 0x1d8(%rbx)
movw $0x0, 0x6e3(%rbx)
movq %rcx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $-0x1, 0x6cc(%rbx)
movw $0x101, 0x6d4(%rbx)     # imm = 0x101
movb $0x0, 0x21860(%rbx)
movq %rcx, 0x1e8(%rbx)
movl $0x15cfe, 0x6e8(%rbx)   # imm = 0x15CFE
movq (%rbx), %rdi
callq 0xa130
movq %rbx, %rdi
movl %eax, %esi
callq 0xdd58
leaq 0x1730(%rbx), %rax
movdqa 0x6c3f(%rip), %xmm0     # 0x148e0
xorl %ecx, %ecx
movq %rax, %xmm1
pshufd $0x44, %xmm1, %xmm1     # xmm1 = xmm1[0,1,0,1]
movdqa 0x6c4b(%rip), %xmm2     # 0x14900
movdqa %xmm1, %xmm3
paddq %xmm0, %xmm3
movdqu %xmm3, 0x1750(%rbx,%rcx,8)
addq $0x2, %rcx
paddq %xmm2, %xmm0
cmpq $0x20, %rcx
jne 0xdcb5
movq %rax, 0x17d0(%rbx)
leaq 0x1734(%rbx), %rax
movq %rax, 0x17f0(%rbx)
leaq 0x1738(%rbx), %rax
movq %rax, 0x1810(%rbx)
leaq 0x173c(%rbx), %rax
movq %rax, 0x1830(%rbx)
addq $0x1850, %rbx           # imm = 0x1850
movl $0x20000, %edx          # imm = 0x20000
movq %rbx, %rdi
xorl %esi, %esi
callq 0x4220
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq %rax, %rbx
jmp 0xdd47
movq %rax, %rbx
movq (%r15), %rdi
cmpq %r15, %rdi
je 0xdd47
movq (%rdi), %r12
callq 0x4380
movq %r12, %rdi
cmpq %r15, %r12
jne 0xdd37
movq %r14, %rdi
callq 0x1212c
movq %rbx, %rdi
callq 0x4610
nop