// File: /workspace/github_cpp_makefile_star2_O3/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:
movb 0xfae3(%rip), %cl       # 0x1c6c1
movzwl %di, %eax
cmpb $0x1, %cl
jne 0xcc0e
movq 0xf87b(%rip), %rdx      # 0x1c468
movl %eax, %edi
shrl $0x8, %edi
movb (%rdx,%rdi), %dl
movl %edx, %edi
andb $0x8, %dil
shrb $0x3, %dil
testb $0x3, %dl
sete %dl
orb %dil, %dl
jne 0xcd83
movq 0x80fc2b(%rip), %rdx    # 0x81c840
testq %rdx, %rdx
je 0xcd0c
movl 0x80fc10(%rip), %edi    # 0x81c834
testl %edi, %edi
je 0xcd0c
cmpl $-0x1, %edi
jne 0xccbc
cmpb $0x6, (%rdx)
jne 0xcd0c
movb %sil, 0x4(%rdx)
movzbl %sil, %eax
leaq 0x6d03(%rip), %rcx      # 0x13950
movsbl (%rax,%rcx), %eax
movl %eax, 0x80fbdd(%rip)    # 0x81c834
movq 0x80fbe2(%rip), %rcx    # 0x81c840
movb $0x0, 0x5(%rcx)
testl %eax, %eax
jne 0xcd83
pushq %rax
movq 0x80fbce(%rip), %rax    # 0x81c840
movb $0x7, (%rax)
cmpb $0x1, 0x80fbcc(%rip)    # 0x81c848
jne 0xcc88
movl $0x1, %edi
callq 0x7f20
cmpb $0x1, 0x80fbba(%rip)    # 0x81c849
jne 0xccac
movq 0x80fba8(%rip), %rax    # 0x81c840
cmpb $0x60, 0x4(%rax)
jne 0xccac
movb $0x0, 0x80fba4(%rip)    # 0x81c849
movb $0x1, 0x80fb9c(%rip)    # 0x81c848
movq $0x0, 0x80fb89(%rip) # 0x81c840
addq $0x8, %rsp
retq
cmpb $0x6, (%rdx)
jne 0xcd0c
movzbl 0x5(%rdx), %eax
movb %sil, 0x6(%rdx,%rax)
movq 0x80fb6f(%rip), %rax    # 0x81c840
incb 0x5(%rax)
decl 0x80fb5a(%rip)          # 0x81c834
jne 0xcd83
movq 0x80fb59(%rip), %rax    # 0x81c840
movb $0x7, (%rax)
movq $0x0, 0x80fb4b(%rip) # 0x81c840
cmpb $0x1, 0x80fb4c(%rip)    # 0x81c848
jne 0xcd83
movl $0x1, %edi
jmp 0x7f20
testb %cl, %cl
je 0xcd22
movq 0xf751(%rip), %rcx      # 0x1c468
movl %eax, %edx
shrl $0x8, %edx
cmpb $0x0, (%rcx,%rdx)
js 0xcd83
movslq 0xf5cf(%rip), %rcx      # 0x1c2f8
movl 0x80fb01(%rip), %edi    # 0x81c830
leal 0x1(%rcx), %edx
andl $0x7ffff, %edx          # imm = 0x7FFFF
cmpl %edi, %ecx
jne 0xcd44
movl %edx, 0x80faee(%rip)    # 0x81c830
movl %edx, %edi
movslq %edi, %rdi
shlq $0x4, %rdi
leaq 0xfade(%rip), %r8       # 0x1c830
movb $0x0, (%rdi,%r8)
shlq $0x4, %rcx
movb $0x2, (%rcx,%r8)
movl %edx, 0xf592(%rip)      # 0x1c2f8
movw %ax, 0x4(%rcx,%r8)
movb %sil, 0x6(%rcx,%r8)
movq 0xf6f0(%rip), %rdx      # 0x1c468
shrl $0x8, %eax
movb (%rdx,%rax), %al
movb %al, 0x7(%rcx,%r8)
retq