// File: /workspace/github_cpp_makefile_star2_O1/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 0xefb1(%rip), %xmm0     # 0x1ada0
movaps %xmm0, 0x40(%rsp)
movaps 0xef95(%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 0xeb8a
movq 0x10560(%rip), %rbp     # 0x1c388
movq 0x10561(%rip), %r15     # 0x1c390
cmpq %r15, %rbp
je 0xbf08
movq (%rsp), %rax
leaq (%rsp,%rax,8), %rbx
addq $0x30, %rbx
movq %r13, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf2f4
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xf013
movq %r12, %rdi
callq 0x6140
movq %rax, %r14
movq %r12, %rdi
callq 0xe8d0
movq %r13, %rdi
callq 0xe8d0
testb %r14b, %r14b
je 0xbe8d
movzbl %r14b, %eax
cmpl $0xff, %eax
jne 0xbe98
addq $0x28, %rbp
cmpq %r15, %rbp
jne 0xbe44
jmp 0xbf08
movq %r13, %rdi
movq %rbx, %rsi
movl $0x2, %edx
callq 0xf2f4
movq %r12, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0xf013
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 0xbef0
leaq 0x28(%rsp), %rdi
callq 0x60e0
movq %r12, %rdi
callq 0xfbcc
movq %r12, %rdi
callq 0xe8d0
movq %r13, %rdi
callq 0xe8d0
movq (%rsp), %r14
movq %r14, %rax
shlq $0x4, %rax
movq 0x1054e(%rip), %rcx     # 0x1c468
movaps 0xa5df(%rip), %xmm0     # 0x16500
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 0xbfab
movq 0x10508(%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 0xbfa3
movq %r12, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x6410
movq 0x88(%rsp), %rax
addq %rax, %rbx
subq %rax, %rbp
jne 0xbf6f
movq %r12, %rdi
callq 0x6080
movq %r12, %rdi
callq 0x60d0
movq %r15, %rdi
callq 0xe8d0
incq %r14
cmpq $0x4, %r14
jne 0xbe15
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xbff4
jmp 0xbff9
jmp 0xbfe2
jmp 0xbff4
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x60d0
jmp 0xc018
movq %rax, %rbx
jmp 0xc018
movq %rax, %rbx
jmp 0xc00e
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0xe8d0
leaq 0x58(%rsp), %rdi
callq 0xe8d0
leaq 0x8(%rsp), %rdi
callq 0xe8d0
movq %rbx, %rdi
callq 0x6550