// File: /workspace/github_cpp_makefile_star2_O3/rockytriton[P]dreamsys_emu_gb/src/cart.cpp
// Function: dsemu::cart::load(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
bool load(const string &romFile) {
    std::ifstream in(romFile, std::ios::binary);

    if (!in) {
        cout << "Unable to open ROM: " << romFile << " - " << strerror(errno) << endl;
        return false;
    }

    if (g_romData != nullptr) {
        delete[] g_romData;
    }

    in.seekg(0, in.end);
    g_romSize = in.tellg();
    in.seekg(0, in.beg);

    g_romData = new byte[g_romSize];

    in.read((char *)g_romData, g_romSize);

    memcpy(&g_header, g_romData + 0x100, sizeof(Header));
    in.close();

    cout << "Loaded Rom: " << romFile << endl;
    cout << "\t    Size: " << g_romSize << endl;
    cout << "\t   Title: " << g_header.title << endl;
    cout << "\tCart Typ: " << Byte(g_header.cartType) << endl;
    cout << "\tCGB Flag: " << Byte(g_header.gbcFlag) << endl;
    cout << "\tSGB Flag: " << Byte(g_header.sgbFlag) << endl;
    cout << "\tROM Size: " << Byte(g_header.romSize) << endl;
    cout << "\tRAM Size: " << Byte(g_header.ramSize) << endl;
    cout << "\tJap Flag: " << Byte(g_header.japFlag) << endl;
    cout << "\t   Entry: " << Byte(g_header.entry[0]) << " "
                           << Byte(g_header.entry[1]) << " "
                           << Byte(g_header.entry[2]) << " "
                           << Byte(g_header.entry[3]) << endl;

    switch(g_header.cartType) {
        case 0: {
            mapper = new mappers::NROMMapper();
        } break;
        case 1: {
            mapper = new mappers::MPC1();
        } break;
        default: {
            cout << "UNSUPPORTED MAPPER" << endl;
            exit(-1);
        }
    }

    return true;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
movq %rsp, %r14
movq %r14, %rdi
movq %rbx, %rsi
movl $0x4, %edx
callq 0x33b0
movq (%r14), %rax
movq -0x18(%rax), %rax
movl 0x20(%rsp,%rax), %r15d
testb $0x5, %r15b
je 0xbae6
movq 0xc558(%rip), %rdi      # 0x17fd0
leaq 0x7585(%rip), %rsi      # 0x13004
movl $0x14, %edx
callq 0x3300
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0xc539(%rip), %rdi      # 0x17fd0
callq 0x3300
movq %rax, %rbx
leaq 0x7573(%rip), %rsi      # 0x13019
movl $0x3, %edx
movq %rax, %rdi
callq 0x3300
callq 0x3050
movl (%rax), %edi
callq 0x30f0
testq %rax, %rax
je 0xc3a5
movq %rax, %r14
movq %rax, %rdi
callq 0x3130
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3300
jmp 0xc3be
movq 0xc7eb(%rip), %rdi      # 0x182d8
testq %rdi, %rdi
je 0xbaf7
callq 0x3330
movq %rsp, %rdi
xorl %esi, %esi
movl $0x2, %edx
callq 0x3340
movq %rsp, %rdi
callq 0x3430
movl %eax, 0xc7cc(%rip)      # 0x182e0
movq %rsp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3340
movslq 0xc7b9(%rip), %r14      # 0x182e0
movq %r14, %rdi
callq 0x3030
movq %rax, 0xc7a2(%rip)      # 0x182d8
movq %rsp, %rdi
movq %rax, %rsi
movq %r14, %rdx
callq 0x3320
movl $0x100, %esi            # imm = 0x100
addq 0xc788(%rip), %rsi      # 0x182d8
leaq 0xc722(%rip), %rdi      # 0x18279
movl $0x51, %edx
callq 0x3230
movq %rsp, %rdi
callq 0x30a0
movq 0xc460(%rip), %rdi      # 0x17fd0
leaq 0x74a6(%rip), %rsi      # 0x1301d
movl $0xc, %edx
callq 0x3300
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq 0xc441(%rip), %rdi      # 0x17fd0
callq 0x3300
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc40b(%rip), %rdi      # 0x17fd0
leaq 0x745e(%rip), %rsi      # 0x1302a
movl $0xb, %edx
callq 0x3300
movl 0xc704(%rip), %esi      # 0x182e0
movq 0xc3ed(%rip), %rdi      # 0x17fd0
callq 0x3420
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc3b7(%rip), %rdi      # 0x17fd0
leaq 0x7416(%rip), %rsi      # 0x13036
movl $0xb, %edx
callq 0x3300
leaq 0xc67c(%rip), %r14      # 0x182ad
movq %r14, %rdi
callq 0x3130
movq 0xc390(%rip), %rbx      # 0x17fd0
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3300
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xc364(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc350(%rip), %rbx      # 0x17fd0
leaq 0x73bb(%rip), %rsi      # 0x13042
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc626(%rip), %ebp      # 0x182c1
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xbcda
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xc2a4(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc290(%rip), %rbx      # 0x17fd0
leaq 0x7307(%rip), %rsi      # 0x1304e
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc562(%rip), %ebp      # 0x182bd
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xbd9a
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xc1e4(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc1d0(%rip), %rbx      # 0x17fd0
leaq 0x7253(%rip), %rsi      # 0x1305a
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc4a5(%rip), %ebp      # 0x182c0
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xbe5a
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xc124(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc110(%rip), %rbx      # 0x17fd0
leaq 0x719f(%rip), %rsi      # 0x13066
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc3e7(%rip), %ebp      # 0x182c2
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xbf1a
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xc064(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc050(%rip), %rbx      # 0x17fd0
leaq 0x70eb(%rip), %rsi      # 0x13072
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc328(%rip), %ebp      # 0x182c3
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xbfda
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xbfa4(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xbf90(%rip), %rbx      # 0x17fd0
leaq 0x7037(%rip), %rsi      # 0x1307e
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc269(%rip), %ebp      # 0x182c4
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xc09a
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xbee4(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xbed0(%rip), %rbx      # 0x17fd0
leaq 0x6f83(%rip), %rsi      # 0x1308a
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc15e(%rip), %ebp      # 0x18279
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xc15a
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq 0xbe3b(%rip), %rbx      # 0x17fd0
leaq 0x6f11(%rip), %rsi      # 0x130ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc0ca(%rip), %ebp      # 0x1827a
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xc1ef
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq 0xbda6(%rip), %rbx      # 0x17fd0
leaq 0x6e7c(%rip), %rsi      # 0x130ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc036(%rip), %ebp      # 0x1827b
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xc284
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq 0xbd11(%rip), %rbx      # 0x17fd0
leaq 0x6de7(%rip), %rsi      # 0x130ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xbfa2(%rip), %ebp      # 0x1827c
movq (%rbx), %rax
movq -0x18(%rax), %rcx
movl 0x18(%rbx,%rcx), %edx
andl $-0x4b, %edx
orl $0x8, %edx
movl %edx, 0x18(%rbx,%rcx)
movq -0x18(%rax), %rcx
leaq (%rbx,%rcx), %r14
cmpb $0x0, 0xe1(%rbx,%rcx)
jne 0xc319
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb $0x1, 0xe1(%r14)
movq (%rbx), %rax
movb $0x30, 0xe0(%r14)
movq -0x18(%rax), %rax
movq $0x2, 0x10(%rbx,%rax)
movq %rbx, %rdi
movl %ebp, %esi
callq 0x3420
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movl 0x18(%rax,%rcx), %edx
andl $-0x4b, %edx
orl $0x2, %edx
movl %edx, 0x18(%rax,%rcx)
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq 0xbc65(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movzbl 0xbf42(%rip), %eax      # 0x182c1
testl %eax, %eax
je 0xc3e7
cmpl $0x1, %eax
jne 0xc425
movl $0x10, %edi
callq 0x32a0
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0xb995(%rip), %rcx      # 0x17d38
jmp 0xc3f8
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq %rbx, %rdi
addq %rax, %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x3400
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x3280
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31a0
jmp 0xc406
movl $0x8, %edi
callq 0x32a0
leaq 0xb908(%rip), %rcx      # 0x17d00
addq $0x10, %rcx
movq %rcx, (%rax)
movq %rax, 0xbeca(%rip)      # 0x182d0
testb $0x5, %r15b
sete %bl
movq %rsp, %rdi
callq 0x30b0
movl %ebx, %eax
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq 0xbba4(%rip), %rdi      # 0x17fd0
leaq 0x6c63(%rip), %rsi      # 0x13096
movl $0x12, %edx
callq 0x3300
movq 0xbb8c(%rip), %rdi      # 0x17fd0
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
jmp 0xc455
movq %rax, %rbx
movq %rsp, %rdi
callq 0x30b0
movq %rbx, %rdi
callq 0x3440