// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: LogStep
void LogStep()
{
	extern uint32_t clockticks6502;
	extern uint16_t pc;
	extern uint8_t sp, a, x, y, status;
	static dlogentry* laststateentry = nullptr, * lastinstentry = nullptr, * lastboringentry = nullptr;
	bool newsuppresslogging = (bool)(syspflags[pc >> 8] & pageflags::PF_DONTLOG);
	if (newsuppresslogging && !suppresslogging)
	{
		if (laststateentry && lastinstentry)
			lastinstentry->instentry.cycles = clockticks6502 - laststateentry->stateentry.ticks;
		lastboringentry = ExtendLog(dletype::LT_BORING);
		lastboringentry->boringentry.entryclock = clockticks6502;
		lastboringentry->boringentry.complete = false;
		lastinstentry = nullptr;
	}
	else if (!newsuppresslogging && suppresslogging)
	{
		lastboringentry->boringentry.exitclock = clockticks6502;
		lastboringentry->boringentry.complete = true;
	}
	suppresslogging = newsuppresslogging;
	if (suppresslogging)
		return;
	if (partialinst && partialinst->entrytype == dletype::LT_PARTIALINST)
		partialinst->entrytype = dletype::LT_INST;
	dlogentry* newentry = ExtendLog(dletype::LT_STATE);
	newentry->stateentry.ticks = clockticks6502;
	newentry->stateentry.pc = pc;
	newentry->stateentry.sp = sp;
	newentry->stateentry.a = a;
	newentry->stateentry.x = x;
	newentry->stateentry.y = y;
	newentry->stateentry.status = status;
	if (laststateentry && lastinstentry)
		lastinstentry->instentry.cycles = newentry->stateentry.ticks - laststateentry->stateentry.ticks;
	if (laststateentry && laststateentry->stateentry.sp != newentry->stateentry.sp)
		LogStack(sp);
	laststateentry = newentry;
	lastinstentry = partialinst = ExtendLog(dletype::LT_PARTIALINST);
	debuglogexpectargs = -1;
}

// Assembly:
movq 0x10dfc(%rip), %rcx     # 0x1c468
leaq 0x81610b(%rip), %rax    # 0x82177e
movzwl (%rax), %eax
movl %eax, %edx
shrl $0x8, %edx
movb (%rcx,%rdx), %cl
movl %ecx, %edx
shrb $0x7, %dl
movb 0x11037(%rip), %sil     # 0x1c6c1
testb %cl, %cl
js 0xb6b3
testb %sil, %sil
je 0xb771
leaq 0x8160d6(%rip), %rsi    # 0x821774
movl (%rsi), %esi
movq 0x814d09(%rip), %rdi    # 0x8203b0
movl %esi, 0x8(%rdi)
movb $0x1, 0xc(%rdi)
jmp 0xb771
testb %sil, %sil
je 0xb6bf
movb %dl, 0x11003(%rip)      # 0x1c6c1
retq
movq 0x814cda(%rip), %rsi    # 0x8203a0
testq %rsi, %rsi
setne %r8b
movq 0x814cd4(%rip), %rdi    # 0x8203a8
testq %rdi, %rdi
setne %r9b
andb %r8b, %r9b
cmpb $0x1, %r9b
jne 0xb6f6
leaq 0x816089(%rip), %r8     # 0x821774
movb (%r8), %r8b
subb 0x4(%rsi), %r8b
movb %r8b, 0x9(%rdi)
movslq 0x10bfb(%rip), %rsi     # 0x1c2f8
movl 0x81112d(%rip), %edi    # 0x81c830
cmpl %edi, %esi
jne 0xb715
incl %edi
andl $0x7ffff, %edi          # imm = 0x7FFFF
movl %edi, 0x81111b(%rip)    # 0x81c830
movslq 0x811114(%rip), %rdi    # 0x81c830
shlq $0x4, %rdi
leaq 0x11109(%rip), %r8      # 0x1c830
xorl %r9d, %r9d
movb %r9b, (%rdi,%r8)
movq %rsi, %rdi
shlq $0x4, %rdi
leaq (%r8,%rdi), %r10
movb $0xa, (%rdi,%r8)
incl %esi
andl $0x7ffff, %esi          # imm = 0x7FFFF
movl %esi, 0x10bac(%rip)     # 0x1c2f8
movq %r10, 0x814c5d(%rip)    # 0x8203b0
leaq 0x81601a(%rip), %rsi    # 0x821774
movl (%rsi), %esi
movl %esi, 0x4(%rdi,%r8)
movb %r9b, 0xc(%rdi,%r8)
movq $0x0, 0x814c37(%rip) # 0x8203a8
movb %dl, 0x10f4a(%rip)      # 0x1c6c1
testb %cl, %cl
js 0xb8f5
movq 0x8110ba(%rip), %rcx    # 0x81c840
testq %rcx, %rcx
je 0xb793
cmpb $0x6, (%rcx)
jne 0xb793
movb $0x7, (%rcx)
pushq %r14
pushq %rbx
pushq %rax
movslq 0x10b5a(%rip), %r14     # 0x1c2f8
movl 0x81108c(%rip), %ecx    # 0x81c830
cmpl %ecx, %r14d
jne 0xb7b7
incl %ecx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
movl %ecx, 0x811079(%rip)    # 0x81c830
movl %r14d, %ecx
movslq 0x81106f(%rip), %rdx    # 0x81c830
shlq $0x4, %rdx
leaq 0x11064(%rip), %rbx     # 0x1c830
movb $0x0, (%rdx,%rbx)
shlq $0x4, %r14
movb $0x5, (%r14,%rbx)
incl %ecx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
movl %ecx, 0x10b11(%rip)     # 0x1c2f8
leaq 0x815f86(%rip), %rcx    # 0x821774
movb (%rcx), %cl
movb %cl, 0x4(%r14,%rbx)
movw %ax, 0x6(%r14,%rbx)
leaq 0x815f7a(%rip), %rax    # 0x82177c
movb (%rax), %al
movb %al, 0x8(%r14,%rbx)
leaq 0x815f70(%rip), %rdx    # 0x821780
movb (%rdx), %dl
movb %dl, 0x9(%r14,%rbx)
leaq 0x815f63(%rip), %rdx    # 0x821781
movb (%rdx), %dl
movb %dl, 0xa(%r14,%rbx)
leaq 0x815f56(%rip), %rdx    # 0x821782
movb (%rdx), %dl
movb %dl, 0xb(%r14,%rbx)
leaq 0x815f49(%rip), %rdx    # 0x821783
movb (%rdx), %dl
movb %dl, 0xc(%r14,%rbx)
movq 0x814b58(%rip), %rdx    # 0x8203a0
testq %rdx, %rdx
setne %dil
movq 0x814b52(%rip), %rsi    # 0x8203a8
testq %rsi, %rsi
setne %r8b
andb %dil, %r8b
cmpb $0x1, %r8b
jne 0xb86c
subb 0x4(%rdx), %cl
movb %cl, 0x9(%rsi)
addq %rbx, %r14
testq %rdx, %rdx
je 0xb885
movb 0x8(%rdx), %cl
cmpb 0x8(%r14), %cl
je 0xb885
movzbl %al, %edi
callq 0xc82a
movq %r14, 0x814b14(%rip)    # 0x8203a0
movslq 0x10a65(%rip), %rax     # 0x1c2f8
movl 0x810f97(%rip), %ecx    # 0x81c830
cmpl %ecx, %eax
jne 0xb8ab
incl %ecx
andl $0x7ffff, %ecx          # imm = 0x7FFFF
movl %ecx, 0x810f85(%rip)    # 0x81c830
movslq 0x810f7e(%rip), %rcx    # 0x81c830
shlq $0x4, %rcx
movb $0x0, (%rcx,%rbx)
movq %rax, %rcx
shlq $0x4, %rcx
leaq (%rbx,%rcx), %rdx
movb $0x6, (%rcx,%rbx)
incl %eax
andl $0x7ffff, %eax          # imm = 0x7FFFF
movl %eax, 0x10a22(%rip)     # 0x1c2f8
movq %rdx, 0x810f63(%rip)    # 0x81c840
movq %rdx, 0x814ac4(%rip)    # 0x8203a8
movl $0xffffffff, 0x810f46(%rip) # imm = 0xFFFFFFFF
addq $0x8, %rsp
popq %rbx
popq %r14
retq