// File: nicoeps[P]NicoGB/src/ppu.cpp
// Function: PPU::getPalette(unsigned char)
std::vector<uint32_t> PPU::getPalette(uint8_t palette) {
    const std::vector<uint32_t> PALETTE = {0xfffff6d3, 0xfff9a875, 0xffeb6b6f, 0xff7c3f58};
    std::vector<uint32_t> col = {0, 0, 0, 0};
    for (int i = 0; i <= 6; i += 2) {
        switch ((palette >> i) & 0x3) {
            case 0:
                col[i/2] = PALETTE[0];
                break;
            case 1:
                col[i/2] = PALETTE[1];
                break;
            case 2:
                col[i/2] = PALETTE[2];
                break;
            case 3:
                col[i/2] = PALETTE[3];
                break;
        }
    }
    return col;
}

// Assembly:
subq $0xc8, %rsp
movq %rdi, 0x20(%rsp)
movb %dl, %al
movq %rdi, %rcx
movq %rcx, 0x28(%rsp)
movq %rdi, 0xc0(%rsp)
movq %rsi, 0xb8(%rsp)
movb %al, 0xb7(%rsp)
movl $0xfffff6d3, 0x78(%rsp) # imm = 0xFFFFF6D3
movl $0xfff9a875, 0x7c(%rsp) # imm = 0xFFF9A875
movl $0xffeb6b6f, 0x80(%rsp) # imm = 0xFFEB6B6F
movl $0xff7c3f58, 0x84(%rsp) # imm = 0xFF7C3F58
leaq 0x78(%rsp), %rax
movq %rax, 0x88(%rsp)
movq $0x4, 0x90(%rsp)
leaq 0x77(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x13290
movq 0x30(%rsp), %rcx
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
leaq 0x98(%rsp), %rdi
callq 0x13550
jmp 0x10eff
leaq 0x77(%rsp), %rdi
callq 0xd620
movb $0x0, 0x63(%rsp)
movl $0x0, 0x40(%rsp)
movl $0x0, 0x44(%rsp)
movl $0x0, 0x48(%rsp)
movl $0x0, 0x4c(%rsp)
leaq 0x40(%rsp), %rax
movq %rax, 0x50(%rsp)
movq $0x4, 0x58(%rsp)
leaq 0x3f(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x13290
movq 0x20(%rsp), %rdi
movq 0x18(%rsp), %rcx
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
callq 0x13550
jmp 0x10f6b
leaq 0x3f(%rsp), %rdi
callq 0xd620
movl $0x0, 0x38(%rsp)
cmpl $0x6, 0x38(%rsp)
jg 0x110f9
movzbl 0xb7(%rsp), %eax
movb 0x38(%rsp), %cl
shrl %cl, %eax
andl $0x3, %eax
movl %eax, %ecx
movq %rcx, 0x10(%rsp)
subl $0x3, %eax
ja 0x110e7
movq 0x10(%rsp), %rax
leaq 0x5aef(%rip), %rcx      # 0x16aa4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x77(%rsp), %rdi
callq 0xd620
jmp 0x11129
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x68(%rsp)
movl %eax, 0x64(%rsp)
leaq 0x3f(%rsp), %rdi
callq 0xd620
leaq 0x98(%rsp), %rdi
callq 0xd450
jmp 0x11129
leaq 0x98(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x135e0
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movl 0x38(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
callq 0x134d0
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x110e7
leaq 0x98(%rsp), %rdi
movl $0x1, %esi
callq 0x135e0
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x8(%rsp)
movl 0x38(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
callq 0x134d0
movl 0x8(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x110e7
leaq 0x98(%rsp), %rdi
movl $0x2, %esi
callq 0x135e0
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x4(%rsp)
movl 0x38(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
callq 0x134d0
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
jmp 0x110e7
leaq 0x98(%rsp), %rdi
movl $0x3, %esi
callq 0x135e0
movq 0x20(%rsp), %rdi
movl (%rax), %eax
movl %eax, (%rsp)
movl 0x38(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
movslq %eax, %rsi
callq 0x134d0
movl (%rsp), %ecx
movl %ecx, (%rax)
jmp 0x110e9
movl 0x38(%rsp), %eax
addl $0x2, %eax
movl %eax, 0x38(%rsp)
jmp 0x10f7d
movb $0x1, 0x63(%rsp)
testb $0x1, 0x63(%rsp)
jne 0x1110f
movq 0x20(%rsp), %rdi
callq 0xd450
leaq 0x98(%rsp), %rdi
callq 0xd450
movq 0x28(%rsp), %rax
addq $0xc8, %rsp
retq
movq 0x68(%rsp), %rdi
callq 0x33d0
nopw %cs:(%rax,%rax)