// File: /workspace/github_cpp_makefile_star2_O2/nicoeps[P]NicoGB/src/memory.cpp
// Function: Memory::Memory(Cartridge&, Joypad&, Timer&)
Memory::Memory(Cartridge& cartridge, Joypad& joypad, Timer& timer)
    : cartridge(cartridge), joypad(joypad), timer(timer) {
    vram.reserve(0x2000);
    wram.reserve(0x2000);
    oam.reserve(0xA0);
    io.reserve(0x100);
    hram.reserve(0x7F);
    boot = {
        0x31, 0xFE, 0xFF, 0xAF, 0x21, 0xFF, 0x9F, 0x32, 0xCB, 0x7C, 0x20, 0xFB, 0x21, 0x26, 0xFF, 0x0E,
        0x11, 0x3E, 0x80, 0x32, 0xE2, 0x0C, 0x3E, 0xF3, 0xE2, 0x32, 0x3E, 0x77, 0x77, 0x3E, 0xFC, 0xE0,
        0x47, 0x11, 0xA8, 0x00, 0x21, 0x10, 0x80, 0x1A, 0xCD, 0x95, 0x00, 0xCD, 0x96, 0x00, 0x13, 0x7B,
        0xFE, 0xD8, 0x20, 0xF3, 0x11, 0xD8, 0x00, 0x06, 0x08, 0x1A, 0x13, 0x22, 0x23, 0x05, 0x20, 0xF9,
        0x3E, 0x19, 0xEA, 0x10, 0x99, 0x21, 0x2F, 0x99, 0x0E, 0x0C, 0x3D, 0x28, 0x08, 0x32, 0x0D, 0x20,
        0xF9, 0x2E, 0x0F, 0x18, 0xF3, 0x67, 0x3E, 0x64, 0x57, 0xE0, 0x42, 0x3E, 0x91, 0xE0, 0x40, 0x04,
        0x1E, 0x02, 0x0E, 0x0C, 0xF0, 0x44, 0xFE, 0x90, 0x20, 0xFA, 0x0D, 0x20, 0xF7, 0x1D, 0x20, 0xF2,
        0x0E, 0x13, 0x24, 0x7C, 0x1E, 0x83, 0xFE, 0x62, 0x28, 0x06, 0x1E, 0xC1, 0xFE, 0x64, 0x20, 0x06,
        0x7B, 0xE2, 0x0C, 0x3E, 0x87, 0xE2, 0xF0, 0x42, 0x90, 0xE0, 0x42, 0x15, 0x20, 0xD2, 0x05, 0x20,
        0x4F, 0x16, 0x20, 0x18, 0xCB, 0x4F, 0x06, 0x04, 0xC5, 0xCB, 0x11, 0x17, 0xC1, 0xCB, 0x11, 0x17,
        0x05, 0x20, 0xF5, 0x22, 0x23, 0x22, 0x23, 0xC9, 0xCE, 0xED, 0x66, 0x66, 0xCC, 0x0C, 0x00, 0x0F,
        0x00, 0x01, 0x00, 0x0E, 0x36, 0x66, 0xC6, 0x60, 0xFC, 0xCF, 0x8D, 0xD9, 0xCE, 0xFF, 0x6F, 0xFF,
        0xDC, 0xCC, 0x6E, 0xE6, 0xDD, 0xDC, 0x98, 0x9F, 0xB3, 0xB1, 0x33, 0x3E, 0x66, 0x63, 0xEE, 0x6E,
        0xCC, 0xCF, 0xCC, 0xC8, 0xF7, 0x31, 0xEC, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
        0x21, 0x04, 0x01, 0x11, 0xA8, 0x00, 0x1A, 0x13, 0xBE, 0x00, 0x00, 0x23, 0x7D, 0xFE, 0x34, 0x20,
        0xF5, 0x06, 0x19, 0x78, 0x86, 0x23, 0x05, 0x20, 0xFB, 0x86, 0x20, 0x01, 0x3E, 0x01, 0xE0, 0x50
    };
    init();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdi, %r14
movq %rsi, (%rdi)
movq %rdx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
leaq 0x28(%rdi), %rbx
leaq 0x40(%rdi), %r15
leaq 0x58(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rdi), %r12
leaq 0x88(%rdi), %r13
leaq 0xa0(%rdi), %rbp
movl $0x90, %edx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2140
movl $0x2000, %esi           # imm = 0x2000
movq %rbx, %rdi
movq %r15, 0x10(%rsp)
callq 0x66a0
movl $0x2000, %esi           # imm = 0x2000
movq %r15, %rdi
callq 0x66a0
movl $0xa0, %esi
movq 0x8(%rsp), %rdi
callq 0x66a0
movl $0x100, %esi            # imm = 0x100
movq %r12, %rdi
callq 0x66a0
pushq $0x7f
popq %rsi
movq %r13, %rdi
callq 0x66a0
leaq 0x393e(%rip), %rsi      # 0x9a60
leaq 0x18(%rsp), %r15
movl $0x100, %edx            # imm = 0x100
movq %r15, %rdi
callq 0x21a0
leaq 0x118(%rsp), %rdx
movq %rbp, %rdi
movq %r15, %rsi
callq 0x672a
movq %r14, %rdi
callq 0x61a2
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6163
movq %rax, %r14
movq %rbp, %rdi
callq 0x2830
movq %r13, %rdi
callq 0x2830
movq %r12, %rdi
callq 0x2830
movq 0x8(%rsp), %rdi
callq 0x2830
movq 0x10(%rsp), %rdi
callq 0x2830
movq %rbx, %rdi
callq 0x2830
movq %r14, %rdi
callq 0x22b0