// File: /workspace/github_cpp_makefile_star2_O1/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 0xc3f9
movq %rax, %r14
movq %rax, %rdi
callq 0x3130
movq %rbx, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x3300
jmp 0xc412
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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xbcde
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xc29d(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc289(%rip), %rbx      # 0x17fd0
leaq 0x7300(%rip), %rsi      # 0x1304e
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc55b(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xbda5
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xc1d6(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc1c2(%rip), %rbx      # 0x17fd0
leaq 0x7245(%rip), %rsi      # 0x1305a
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc497(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xbe6c
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xc10f(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc0fb(%rip), %rbx      # 0x17fd0
leaq 0x718a(%rip), %rsi      # 0x13066
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc3d2(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xbf33
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xc048(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xc034(%rip), %rbx      # 0x17fd0
leaq 0x70cf(%rip), %rsi      # 0x13072
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc30c(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xbffa
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xbf81(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xbf6d(%rip), %rbx      # 0x17fd0
leaq 0x7014(%rip), %rsi      # 0x1307e
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc246(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xc0c1
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xbeba(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movq 0xbea6(%rip), %rbx      # 0x17fd0
leaq 0x6f59(%rip), %rsi      # 0x1308a
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc134(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xc188
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xbe0a(%rip), %rbx      # 0x17fd0
leaq 0x6ee0(%rip), %rsi      # 0x130ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xc099(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xc224
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xbd6e(%rip), %rbx      # 0x17fd0
leaq 0x6e44(%rip), %rsi      # 0x130ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xbffe(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xc2c0
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xbcd2(%rip), %rbx      # 0x17fd0
leaq 0x6da8(%rip), %rsi      # 0x130ad
movl $0x1, %edx
movq %rbx, %rdi
callq 0x3300
movzbl 0xbf63(%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), %rax
leaq (%rbx,%rax), %r14
cmpb $0x0, 0xe1(%rbx,%rax)
jne 0xc35c
movq %r14, %rdi
movl $0x20, %esi
callq 0x3280
movb %al, 0xe0(%r14)
movb $0x1, 0xe1(%r14)
movb $0x30, 0xe0(%r14)
movq (%rbx), %rax
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 0xbc1f(%rip), %rdi      # 0x17fd0
callq 0x3040
movq %rax, %rdi
callq 0x31a0
movzbl 0xbefc(%rip), %eax      # 0x182c1
testl %eax, %eax
je 0xc43b
cmpl $0x1, %eax
jne 0xc479
movl $0x10, %edi
callq 0x32a0
xorps %xmm0, %xmm0
movaps %xmm0, (%rax)
leaq 0xb94f(%rip), %rcx      # 0x17d38
addq $0x10, %rcx
movq %rcx, (%rax)
movl $0x0, 0x8(%rax)
jmp 0xc453
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 0xc45a
movl $0x8, %edi
callq 0x32a0
leaq 0xb8b4(%rip), %rcx      # 0x17d00
addq $0x10, %rcx
movq %rcx, (%rax)
movq %rax, 0xbe76(%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 0xbb50(%rip), %rdi      # 0x17fd0
leaq 0x6c0f(%rip), %rsi      # 0x13096
movl $0x12, %edx
callq 0x3300
movq 0xbb38(%rip), %rdi      # 0x17fd0
callq 0x3150
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
callq 0x3310
jmp 0xc4a9
movq %rax, %rbx
movq %rsp, %rdi
callq 0x30b0
movq %rbx, %rdi
callq 0x3440