// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movq %rsi, (%rdi)
movq %rdx, 0x8(%rdi)
movq %rcx, 0x10(%rdi)
leaq 0x28(%rdi), %r14
leaq 0x40(%rdi), %r12
leaq 0x58(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x70(%rdi), %r13
leaq 0x88(%rdi), %rbp
leaq 0xa0(%rdi), %r15
movl $0x90, %edx
movq %r14, %rdi
xorl %esi, %esi
callq 0x2120
movl $0x2000, %esi           # imm = 0x2000
movq %r14, %rdi
movq %r12, 0x10(%rsp)
callq 0x72c2
movl $0x2000, %esi           # imm = 0x2000
movq %r12, %rdi
callq 0x72c2
movl $0xa0, %esi
movq 0x8(%rsp), %rdi
callq 0x72c2
movl $0x100, %esi            # imm = 0x100
movq %r13, %rdi
callq 0x72c2
movl $0x7f, %esi
movq %rbp, %rdi
callq 0x72c2
leaq 0x3d84(%rip), %rsi      # 0xaa3c
leaq 0x18(%rsp), %r12
movl $0x100, %edx            # imm = 0x100
movq %r12, %rdi
callq 0x2180
leaq 0x118(%rsp), %rdx
movq %r15, %rdi
movq %r12, %rsi
callq 0x7354
movq %rbx, %rdi
callq 0x6d92
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6cf9
movq %rax, %r12
movq (%r15), %rdi
testq %rdi, %rdi
je 0x6d13
movq 0xb0(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq (%rbp), %rdi
testq %rdi, %rdi
je 0x6d2b
movq 0x98(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq (%r13), %rdi
testq %rdi, %rdi
je 0x6d43
movq 0x80(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6d5c
movq 0x68(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq 0x10(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0x6d75
movq 0x50(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq (%r14), %rdi
testq %rdi, %rdi
je 0x6d89
movq 0x38(%rbx), %rsi
subq %rdi, %rsi
callq 0x21c0
movq %r12, %rdi
callq 0x2270
nop