// File: /workspace/github_cpp_makefile_star2_O2/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 $0x298, %rsp            # imm = 0x298
movaps 0xefe0(%rip), %xmm0     # 0x19da0
movaps %xmm0, 0x50(%rsp)
movaps 0xefc4(%rip), %xmm0     # 0x19d90
movaps %xmm0, 0x40(%rsp)
movl $0xc0, %eax
movq %rax, 0x8(%rsp)
xorl %r14d, %r14d
leaq 0x90(%rsp), %r15
leaq 0x68(%rsp), %r12
cmpq $0x4, %r14
je 0xaf5e
leaq 0x18(%rsp), %rdi
callq 0xd354
movq 0x10592(%rip), %rbx     # 0x1b398
movq 0x10593(%rip), %r13     # 0x1b3a0
movq %r14, 0x10(%rsp)
leaq (%rsp,%r14,8), %rbp
addq $0x40, %rbp
cmpq %r13, %rbx
je 0xae9a
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x2
popq %rdx
callq 0xdb10
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xd8bb
movq %r15, %rdi
callq 0xd036
movl %eax, %r14d
movq %r15, %rdi
callq 0xd08a
movq %r12, %rdi
callq 0xd08a
testb %r14b, %r14b
jne 0xae61
addq $0x28, %rbx
jmp 0xae1a
movq %r12, %rdi
movq %rbp, %rsi
pushq $0x2
popq %rdx
callq 0xdb10
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0xd8bb
leaq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0xd052
movq %r15, %rdi
callq 0xd08a
movq %r12, %rdi
callq 0xd08a
movq 0x105d7(%rip), %rax     # 0x1b478
addq 0x8(%rsp), %rax
xorl %ecx, %ecx
cmpq $0x10, %rcx
je 0xaeb7
movb $0x1, (%rax,%rcx)
incq %rcx
jmp 0xaea8
movq 0x18(%rsp), %rsi
movq %r15, %rdi
pushq $0x4
popq %rdx
callq 0x65c0
leaq 0x108(%rsp), %rdi
callq 0x60b0
testb %al, %al
je 0xaf39
movq 0x10591(%rip), %rax     # 0x1b470
movq 0x10(%rsp), %rcx
shlq $0xc, %rcx
leaq (%rax,%rcx), %rbx
addq $0xc000, %rbx           # imm = 0xC000
movl $0x1000, %ebp           # imm = 0x1000
testq %rbp, %rbp
je 0xaf31
movq 0x90(%rsp), %rax
movq -0x18(%rax), %rax
cmpl $0x0, 0xb0(%rsp,%rax)
jne 0xaf31
movq %r15, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x6410
movq 0x98(%rsp), %rax
subq %rax, %rbp
addq %rax, %rbx
jmp 0xaef8
movq %r15, %rdi
callq 0x6090
movq %r15, %rdi
callq 0x60e0
leaq 0x18(%rsp), %rdi
callq 0xd08a
movq 0x10(%rsp), %r14
incq %r14
addq $0x10, 0x8(%rsp)
jmp 0xadeb
addq $0x298, %rsp            # imm = 0x298
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xafa1
jmp 0xaf9c
jmp 0xaf78
jmp 0xaf9c
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0x60e0
jmp 0xafae
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
callq 0xd08a
jmp 0xafa4
movq %rax, %rbx
jmp 0xafae
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0xd08a
leaq 0x18(%rsp), %rdi
callq 0xd08a
movq %rbx, %rdi
callq 0x6580