// File: nicoeps[P]NicoGB/src/ppu.cpp
// Function: PPU::PPU(Memory&)
PPU::PPU(Memory& memory) :
    memory(memory),
    lcdc(memory.lcd.lcdc),
    stat(memory.lcd.stat),
    scy(memory.lcd.scy),
    scx(memory.lcd.scx),
    ly(memory.lcd.ly),
    lyc(memory.lcd.lyc),
    bgp(memory.lcd.bgp),
    obp0(memory.lcd.obp0),
    obp1(memory.lcd.obp1),
    wy(memory.lcd.wy),
    wx(memory.lcd.wx) {
    framebuffer = std::vector<uint32_t>(160*144);
    writebuffer = std::vector<uint32_t>(160*144);
    line = std::vector<uint8_t>(160);
    init();
}

// Assembly:
subq $0xd8, %rsp
movq %rdi, 0xd0(%rsp)
movq %rsi, 0xc8(%rsp)
movq 0xd0(%rsp), %rdi
movq %rdi, 0x40(%rsp)
movq 0xc8(%rsp), %rax
movq %rax, (%rdi)
addq $0x8, %rdi
movq %rdi, 0x30(%rsp)
callq 0x13280
movq 0x40(%rsp), %rdi
movq 0xc8(%rsp), %rax
addq $0x18, %rax
movq %rax, 0x28(%rdi)
movq 0xc8(%rsp), %rax
addq $0x19, %rax
movq %rax, 0x30(%rdi)
movq 0xc8(%rsp), %rax
addq $0x1a, %rax
movq %rax, 0x38(%rdi)
movq 0xc8(%rsp), %rax
addq $0x1b, %rax
movq %rax, 0x40(%rdi)
movq 0xc8(%rsp), %rax
addq $0x1c, %rax
movq %rax, 0x48(%rdi)
movq 0xc8(%rsp), %rax
addq $0x1d, %rax
movq %rax, 0x50(%rdi)
movq 0xc8(%rsp), %rax
addq $0x1e, %rax
movq %rax, 0x58(%rdi)
movq 0xc8(%rsp), %rax
addq $0x1f, %rax
movq %rax, 0x60(%rdi)
movq 0xc8(%rsp), %rax
addq $0x20, %rax
movq %rax, 0x68(%rdi)
movq 0xc8(%rsp), %rax
addq $0x21, %rax
movq %rax, 0x70(%rdi)
movq 0xc8(%rsp), %rax
addq $0x22, %rax
movq %rax, 0x78(%rdi)
addq $0x88, %rdi
movq %rdi, 0x38(%rsp)
callq 0x13280
movq 0x40(%rsp), %rdi
addq $0xa0, %rdi
movq %rdi, 0x48(%rsp)
callq 0x3f00
leaq 0xaf(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0x13290
movq 0x50(%rsp), %rdx
leaq 0xb0(%rsp), %rdi
movl $0x5a00, %esi           # imm = 0x5A00
callq 0x132a0
jmp 0x10694
movq 0x40(%rsp), %rdi
addq $0x8, %rdi
leaq 0xb0(%rsp), %rsi
movq %rsi, 0x20(%rsp)
callq 0x13320
movq 0x20(%rsp), %rdi
callq 0xd450
leaq 0xaf(%rsp), %rdi
callq 0xd620
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x28(%rsp)
callq 0x13290
movq 0x28(%rsp), %rdx
leaq 0x80(%rsp), %rdi
movl $0x5a00, %esi           # imm = 0x5A00
callq 0x132a0
jmp 0x106ee
movq 0x40(%rsp), %rdi
addq $0x88, %rdi
leaq 0x80(%rsp), %rsi
movq %rsi, 0x10(%rsp)
callq 0x13320
movq 0x10(%rsp), %rdi
callq 0xd450
leaq 0x7f(%rsp), %rdi
callq 0xd620
leaq 0x5f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x45d0
movq 0x18(%rsp), %rdx
leaq 0x60(%rsp), %rdi
movl $0xa0, %esi
callq 0x13360
jmp 0x10745
movq 0x40(%rsp), %rdi
addq $0xa0, %rdi
leaq 0x60(%rsp), %rsi
movq %rsi, 0x8(%rsp)
callq 0x3f10
movq 0x8(%rsp), %rdi
callq 0x3f50
leaq 0x5f(%rsp), %rdi
callq 0x49c0
movq 0x40(%rsp), %rdi
callq 0x10830
jmp 0x10780
addq $0xd8, %rsp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xaf(%rsp), %rdi
callq 0xd620
jmp 0x107ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0xd620
jmp 0x107ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0x5f(%rsp), %rdi
callq 0x49c0
jmp 0x107ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
movq 0x48(%rsp), %rdi
callq 0x3f50
movq 0x38(%rsp), %rdi
callq 0xd450
movq 0x30(%rsp), %rdi
callq 0xd450
movq 0xa0(%rsp), %rdi
callq 0x33d0
nopw (%rax,%rax)