// File: /workspace/github_cpp_makefile_star2_O2/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 %rbx
subq $0x10, %rsp
movq %rdi, %rbx
movq %rsi, (%rdi)
leaq 0x8(%rdi), %r14
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0xfc60
andq $0x0, 0x1d8(%rbx)
andl $0x0, 0x1e0(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, 0x1b8(%rbx)
movups %xmm0, 0x1c4(%rbx)
leaq 0x1f0(%rbx), %r15
leaq 0xf(%rsp), %rdx
movq %r15, %rdi
xorl %esi, %esi
callq 0xe080
andl $0x0, 0x2185c(%rbx)
movb 0x1b0(%rbx), %al
movb %al, 0x21861(%rbx)
andq $0x0, 0x1d8(%rbx)
leaq 0x1b8(%rbx), %rax
andw $0x0, 0x6e3(%rbx)
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
andq $0x0, 0x10(%rax)
orq $-0x1, 0x6cc(%rbx)
movw $0x101, 0x6d4(%rbx)     # imm = 0x101
movb $0x0, 0x21860(%rbx)
andq $0x0, 0x1e8(%rbx)
movl $0x15cfe, 0x6e8(%rbx)   # imm = 0x15CFE
movq (%rbx), %rdi
callq 0x8efa
movq %rbx, %rdi
movl %eax, %esi
callq 0xc56a
leaq 0x1730(%rbx), %rax
xorl %ecx, %ecx
cmpq $0x20, %rcx
je 0xc49e
leaq (%rax,%rcx), %rdx
movq %rdx, 0x20(%rax,%rcx,8)
incq %rcx
jmp 0xc48a
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
xorl %eax, %eax
cmpq $0x2, %rax
je 0xc540
movq %rbx, %rcx
xorl %edx, %edx
cmpq $0x100, %rdx            # imm = 0x100
je 0xc534
movq %rcx, %rsi
xorl %edi, %edi
cmpq $0x8, %rdi
je 0xc528
movq %rsi, %r8
xorl %r9d, %r9d
cmpq $0x2, %r9
je 0xc51f
xorl %r10d, %r10d
cmpq $0x2, %r10
je 0xc516
andq $0x0, (%r8,%r10,8)
incq %r10
jmp 0xc506
incq %r9
addq $0x10, %r8
jmp 0xc4fd
incq %rdi
addq $0x20, %rsi
jmp 0xc4f1
incq %rdx
addq $0x100, %rcx            # imm = 0x100
jmp 0xc4e3
incq %rax
addq $0x10000, %rbx          # imm = 0x10000
jmp 0xc4d8
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
jmp 0xc55a
movq %rax, %rbx
movq %r15, %rdi
callq 0xe0c8
movq %r14, %rdi
callq 0xff48
movq %rbx, %rdi
callq 0x4640