// File: /workspace/github_cpp_makefile_star2_O3/mdpkh[P]retro6k/src/main.cpp
// Function: InstallROM()
void InstallROM()
{
	const char* infilename[4] = {
		"bankc.rom",
		"bankd.rom",
		"banke.rom",
		"bankf.rom" 
	};
	for (int i = 0; i < 4; ++i)
	{
		std::filesystem::path romfile;
		for (auto& path : config.path.rompath)
		{
			if (std::filesystem::exists(path / std::filesystem::path(infilename[i])))
			{
				romfile = path / std::filesystem::path(infilename[i]);
				break;
			}
		}
		for (int p = 0; p < 16; ++p)
			syspflags[0xc0 | (i << 4) | p] = pageflags::PF_TROM;
		std::ifstream infile(romfile, std::ios::binary);
		if (infile.is_open())
		{
			std::streamsize readsize = 0x1000;
			char* romptr = (char*)sysram + 0xC000ll + 0x1000ll * i;
			while (readsize && infile.good())
			{
				infile.read(romptr, readsize);
				readsize -= infile.gcount();
				romptr += infile.gcount();
			}
			infile.close();
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x288, %rsp            # imm = 0x288
movaps 0xe96c(%rip), %xmm0     # 0x1ada0
movaps %xmm0, 0x40(%rsp)
movaps 0xe950(%rip), %xmm0     # 0x1ad90
movaps %xmm0, 0x30(%rsp)
xorl %r14d, %r14d
leaq 0x8(%rsp), %r15
leaq 0x80(%rsp), %r12
leaq 0x58(%rsp), %r13
movq %r14, (%rsp)
movq %r15, %rdi
callq 0xf16a
movq 0xff1b(%rip), %rbp      # 0x1c388
movq 0xff1c(%rip), %r15      # 0x1c390
cmpq %r15, %rbp
je 0xc54d
movq (%rsp), %rax
leaq (%rsp,%rax,8), %rbx
addq $0x30, %rbx
movq %r13, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf8dc
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xf5fb
movq %r12, %rdi
callq 0x6140
movq %rax, %r14
movq %r12, %rdi
callq 0xeeb0
movq %r13, %rdi
callq 0xeeb0
testb %r14b, %r14b
je 0xc4d2
movzbl %r14b, %eax
cmpl $0xff, %eax
jne 0xc4dd
addq $0x28, %rbp
cmpq %r15, %rbp
jne 0xc489
jmp 0xc54d
movq %r13, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf8dc
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xf5fb
leaq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x6400
movq 0xa0(%rsp), %rax
movq $0x0, 0xa0(%rsp)
movq 0x28(%rsp), %rsi
movq %rax, 0x28(%rsp)
testq %rsi, %rsi
je 0xc535
leaq 0x28(%rsp), %rdi
callq 0x60e0
movq %r12, %rdi
callq 0x10128
movq %r12, %rdi
callq 0xeeb0
movq %r13, %rdi
callq 0xeeb0
movq (%rsp), %r14
movq %r14, %rax
shlq $0x4, %rax
movq 0xff09(%rip), %rcx      # 0x1c468
movaps 0x6baa(%rip), %xmm0     # 0x13110
movups %xmm0, 0xc0(%rcx,%rax)
movq 0x8(%rsp), %rsi
movq %r12, %rdi
movl $0x4, %edx
callq 0x6590
leaq 0xf8(%rsp), %rdi
callq 0x60a0
testb %al, %al
leaq 0x8(%rsp), %r15
je 0xc5f0
movq 0xfec3(%rip), %rax      # 0x1c460
movq %r14, %rcx
shlq $0xc, %rcx
leaq (%rax,%rcx), %rbx
addq $0xc000, %rbx           # imm = 0xC000
movl $0x1000, %ebp           # imm = 0x1000
movq 0x80(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0xa0(%rsp,%rax)
jne 0xc5e8
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x6410
movq 0x88(%rsp), %rax
addq %rax, %rbx
subq %rax, %rbp
jne 0xc5b4
movq %r12, %rdi
callq 0x6080
movq %r12, %rdi
callq 0x60d0
movq %r15, %rdi
callq 0xeeb0
incq %r14
cmpq $0x4, %r14
jne 0xc45a
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc639
jmp 0xc63e
jmp 0xc627
jmp 0xc639
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x60d0
jmp 0xc65d
movq %rax, %rbx
jmp 0xc65d
movq %rax, %rbx
jmp 0xc653
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xeeb0
leaq 0x58(%rsp), %rdi
callq 0xeeb0
leaq 0x8(%rsp), %rdi
callq 0xeeb0
movq %rbx, %rdi
callq 0x6550