// File: /workspace/github_cpp_makefile_star2_O2/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
movl %edi, %ebp
movb 0x1022f(%rip), %al      # 0x1b6d1
movzwl %bp, %r14d
cmpb $0x1, %al
jne 0xb4d0
movq 0xffc7(%rip), %rcx      # 0x1b478
movl %r14d, %edx
shrl $0x8, %edx
movb (%rcx,%rdx), %cl
movl %ecx, %edx
andb $0x8, %dl
shrb $0x3, %dl
testb $0x3, %cl
sete %cl
orb %dl, %cl
jne 0xb5ee
movq 0x810379(%rip), %rcx    # 0x81b850
testq %rcx, %rcx
je 0xb5b5
movl 0x81035e(%rip), %edx    # 0x81b844
testl %edx, %edx
je 0xb5b5
cmpl $-0x1, %edx
jne 0xb56f
cmpb $0x6, (%rcx)
jne 0xb5b5
movb %bl, 0x4(%rcx)
movzbl %bl, %eax
leaq 0x6377(%rip), %rcx      # 0x11880
movsbl (%rax,%rcx), %eax
movl %eax, 0x810331(%rip)    # 0x81b844
movq 0x810336(%rip), %rcx    # 0x81b850
movb $0x0, 0x5(%rcx)
testl %eax, %eax
jne 0xb5ee
movq 0x810323(%rip), %rax    # 0x81b850
movb $0x7, (%rax)
cmpb $0x1, 0x810321(%rip)    # 0x81b858
jne 0xb541
pushq $0x1
popq %rdi
callq 0x7397
cmpb $0x1, 0x810311(%rip)    # 0x81b859
jne 0xb565
movq 0x8102ff(%rip), %rax    # 0x81b850
cmpb $0x60, 0x4(%rax)
jne 0xb565
movb $0x0, 0x8102fb(%rip)    # 0x81b859
movb $0x1, 0x8102f3(%rip)    # 0x81b858
andq $0x0, 0x8102e3(%rip)    # 0x81b850
jmp 0xb5ee
cmpb $0x6, (%rcx)
jne 0xb5b5
movzbl 0x5(%rcx), %eax
movb %bl, 0x6(%rcx,%rax)
movq 0x8102cd(%rip), %rax    # 0x81b850
incb 0x5(%rax)
decl 0x8102b8(%rip)          # 0x81b844
jne 0xb5ee
movq 0x8102bb(%rip), %rax    # 0x81b850
movb $0x7, (%rax)
andq $0x0, 0x8102b0(%rip)    # 0x81b850
cmpb $0x1, 0x8102b1(%rip)    # 0x81b858
jne 0xb5ee
pushq $0x1
popq %rdi
popq %rbx
popq %r14
popq %rbp
jmp 0x7397
testb %al, %al
je 0xb5cd
movq 0xfeb8(%rip), %rax      # 0x1b478
shrl $0x8, %r14d
cmpb $0x0, (%rax,%r14)
jns 0xb5d1
jmp 0xb5ee
shrl $0x8, %r14d
pushq $0x2
popq %rdi
callq 0xa0c1
movw %bp, 0x4(%rax)
movb %bl, 0x6(%rax)
movq 0xfe91(%rip), %rcx      # 0x1b478
movb (%rcx,%r14), %cl
movb %cl, 0x7(%rax)
popq %rbx
popq %r14
popq %rbp
retq