// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: LogRead(unsigned short, unsigned char)
void LogRead(uint16_t address, uint8_t value)
{
	if (suppresslogging && ((bool)(syspflags[address >> 8] & pageflags::PF_IO)
		|| ((syspflags[address >> 8] & pageflags::PF_TMASK) == pageflags::PF_TFLOATING)))
		return;
	if (!partialinst)
		goto logmementry;
	if (debuglogexpectargs == -1)
	{
		const char nargsbyopcode[256] = {
			/*      0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F */
			/* 0 */ 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* 0 */
			/* 1 */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* 1 */
			/* 2 */ 2, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* 2 */
			/* 3 */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* 3 */
			/* 4 */ 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* 4 */
			/* 5 */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* 5 */
			/* 6 */ 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* 6 */
			/* 7 */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* 7 */
			/* 8 */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* 8 */
			/* 9 */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* 9 */
			/* A */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* A */
			/* B */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* B */
			/* C */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* C */
			/* D */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2, /* D */
			/* E */ 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 2, 2, 2, 2, /* E */
			/* F */ 1, 1, 0, 1, 1, 1, 1, 1, 0, 2, 0, 2, 2, 2, 2, 2  /* F */
		};
		if (partialinst->entrytype != dletype::LT_PARTIALINST)
			goto logmementry;
		partialinst->instentry.opc = value;
		debuglogexpectargs = nargsbyopcode[value];
		partialinst->instentry.nargs = 0;
		if (!debuglogexpectargs)
		{
			partialinst->entrytype = dletype::LT_INST;
			if (breakpreexecute)
				DoDebugger();
			if (breakafterrts && partialinst->instentry.opc == 0x60)
			{
				breakafterrts = false;
				breakpreexecute = true;
			}
			partialinst = nullptr;
		}
	}
	else if (debuglogexpectargs)
	{
		if (partialinst->entrytype != dletype::LT_PARTIALINST)
			goto logmementry;
		partialinst->instentry.arg[partialinst->instentry.nargs] = value;
		++(partialinst->instentry.nargs);
		--debuglogexpectargs;
		if (!debuglogexpectargs)
		{
			partialinst->entrytype = dletype::LT_INST;
			partialinst = nullptr;
			if (breakpreexecute)
				DoDebugger();
		}
	}
	else
	{
	logmementry:
		if (suppresslogging && (bool)(syspflags[address >> 8] & pageflags::PF_DONTLOG))
			return;
		dlogentry* newentry = ExtendLog(dletype::LT_READ);
		newentry->mementry.address = address;
		newentry->mementry.value = value;
		newentry->mementry.memtype = syspflags[address >> 8];
	}
}

// Assembly:
pushq %rbp
pushq %r14
pushq %rbx
movl %esi, %ebx
cmpb $0x1, 0x1011b(%rip)     # 0x1c6c1
movzwl %di, %r14d
jne 0xc5d1
movq 0xfeb5(%rip), %rax      # 0x1c468
movl %r14d, %ecx
shrl $0x8, %ecx
movb (%rax,%rcx), %al
movl %eax, %ecx
andb $0x8, %cl
shrb $0x3, %cl
testb $0x3, %al
sete %al
orb %cl, %al
jne 0xc75b
movq 0x810268(%rip), %rax    # 0x81c840
testq %rax, %rax
je 0xc6d5
movl 0x81024d(%rip), %ecx    # 0x81c834
testl %ecx, %ecx
je 0xc6d5
cmpl $-0x1, %ecx
jne 0xc682
movb (%rax), %bpl
cmpb $0x6, %bpl
jne 0xc6d5
movb %bl, 0x4(%rax)
movzbl %bl, %eax
leaq 0x71ee(%rip), %rcx      # 0x13800
movsbl (%rax,%rcx), %eax
movl %eax, 0x810218(%rip)    # 0x81c834
movq 0x81021d(%rip), %rcx    # 0x81c840
movb $0x0, 0x5(%rcx)
testl %eax, %eax
jne 0xc677
movq 0x81020e(%rip), %rax    # 0x81c840
movb $0x7, (%rax)
cmpb $0x1, 0x81020c(%rip)    # 0x81c848
jne 0xc648
movl $0x1, %edi
callq 0x785d
cmpb $0x1, 0x8101fa(%rip)    # 0x81c849
jne 0xc66c
movq 0x8101e8(%rip), %rax    # 0x81c840
cmpb $0x60, 0x4(%rax)
jne 0xc66c
movb $0x0, 0x8101e4(%rip)    # 0x81c849
movb $0x1, 0x8101dc(%rip)    # 0x81c848
movq $0x0, 0x8101c9(%rip) # 0x81c840
cmpb $0x6, %bpl
jne 0xc6d5
jmp 0xc75b
cmpb $0x6, (%rax)
jne 0xc6d5
movzbl 0x5(%rax), %ecx
movb %bl, 0x6(%rax,%rcx)
movq 0x8101aa(%rip), %rax    # 0x81c840
incb 0x5(%rax)
decl 0x810195(%rip)          # 0x81c834
jne 0xc75b
movq 0x810194(%rip), %rax    # 0x81c840
movb $0x7, (%rax)
movq $0x0, 0x810186(%rip) # 0x81c840
cmpb $0x1, 0x810187(%rip)    # 0x81c848
jne 0xc75b
movl $0x1, %edi
popq %rbx
popq %r14
popq %rbp
jmp 0x785d
cmpb $0x1, 0xffe5(%rip)      # 0x1c6c1
jne 0xc6f1
movq 0xfd83(%rip), %rax      # 0x1c468
movl %r14d, %ecx
shrl $0x8, %ecx
cmpb $0x0, (%rax,%rcx)
js 0xc75b
movslq 0xfc00(%rip), %rax      # 0x1c2f8
movl 0x810132(%rip), %ecx    # 0x81c830
cmpl %ecx, %eax
jne 0xc710
incl %ecx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
movl %ecx, 0x810120(%rip)    # 0x81c830
movslq 0x810119(%rip), %rcx    # 0x81c830
shlq $0x4, %rcx
leaq 0x1010e(%rip), %rdx     # 0x1c830
movb $0x0, (%rcx,%rdx)
movq %rax, %rcx
shlq $0x4, %rcx
movb $0x2, (%rcx,%rdx)
incl %eax
andl $0x7ffff, %eax          # imm = 0x7FFFF
movl %eax, 0xfbba(%rip)      # 0x1c2f8
movw %r14w, 0x4(%rcx,%rdx)
movb %bl, 0x6(%rcx,%rdx)
movq 0xfd19(%rip), %rax      # 0x1c468
shrl $0x8, %r14d
movb (%rax,%r14), %al
movb %al, 0x7(%rcx,%rdx)
popq %rbx
popq %r14
popq %rbp
retq