// File: 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:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq 0x1f3b9(%rip), %rax     # 0x2d568
leaq 0x8246b8(%rip), %rcx    # 0x83286e
movzwl (%rcx), %ecx
sarl $0x8, %ecx
movslq %ecx, %rcx
movl $0xffffff80, %esi       # imm = 0xFFFFFF80
movsbl (%rax,%rcx), %edi
callq 0x7990
cmpb $0x0, %al
setne %al
andb $0x1, %al
movb %al, -0x1(%rbp)
testb $0x1, -0x1(%rbp)
je 0xe258
testb $0x1, 0x1f5dd(%rip)     # 0x2d7c1
jne 0xe258
cmpq $0x0, 0x8232a2(%rip)    # 0x831490
je 0xe21c
cmpq $0x0, 0x8232a0(%rip)    # 0x831498
je 0xe21c
leaq 0x824663(%rip), %rax    # 0x832864
movl (%rax), %eax
movq 0x823286(%rip), %rcx    # 0x831490
movzbl 0x4(%rcx), %ecx
subl %ecx, %eax
movb %al, %cl
movq 0x82327f(%rip), %rax    # 0x831498
movb %cl, 0x9(%rax)
movl $0xa, %edi
callq 0xd3d0
movq %rax, 0x823273(%rip)    # 0x8314a0
leaq 0x824630(%rip), %rax    # 0x832864
movl (%rax), %ecx
movq 0x823263(%rip), %rax    # 0x8314a0
movl %ecx, 0x4(%rax)
movq 0x823259(%rip), %rax    # 0x8314a0
movb $0x0, 0xc(%rax)
movq $0x0, 0x823242(%rip) # 0x831498
jmp 0xe287
testb $0x1, -0x1(%rbp)
jne 0xe285
testb $0x1, 0x1f55c(%rip)     # 0x2d7c1
je 0xe285
leaq 0x8245f6(%rip), %rax    # 0x832864
movl (%rax), %ecx
movq 0x823229(%rip), %rax    # 0x8314a0
movl %ecx, 0x8(%rax)
movq 0x82321f(%rip), %rax    # 0x8314a0
movb $0x1, 0xc(%rax)
jmp 0xe287
movb -0x1(%rbp), %al
andb $0x1, %al
movb %al, 0x1f52f(%rip)      # 0x2d7c1
testb $0x1, 0x1f528(%rip)     # 0x2d7c1
je 0xe2a0
jmp 0xe3d4
cmpq $0x0, 0x81f698(%rip)    # 0x82d940
je 0xe2c0
movq 0x81f68f(%rip), %rax    # 0x82d940
cmpb $0x6, (%rax)
jne 0xe2c0
movq 0x81f683(%rip), %rax    # 0x82d940
movb $0x7, (%rax)
movl $0x5, %edi
callq 0xd3d0
movq %rax, -0x10(%rbp)
leaq 0x82458f(%rip), %rax    # 0x832864
movl (%rax), %eax
movb %al, %cl
movq -0x10(%rbp), %rax
movb %cl, 0x4(%rax)
leaq 0x824587(%rip), %rax    # 0x83286e
movw (%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x6(%rax)
leaq 0x824573(%rip), %rax    # 0x83286c
movb (%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x8(%rax)
leaq 0x824567(%rip), %rax    # 0x832870
movb (%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0x9(%rax)
leaq 0x824558(%rip), %rax    # 0x832871
movb (%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0xa(%rax)
leaq 0x824549(%rip), %rax    # 0x832872
movb (%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0xb(%rax)
leaq 0x82453a(%rip), %rax    # 0x832873
movb (%rax), %cl
movq -0x10(%rbp), %rax
movb %cl, 0xc(%rax)
cmpq $0x0, 0x823146(%rip)    # 0x831490
je 0xe377
cmpq $0x0, 0x823144(%rip)    # 0x831498
je 0xe377
movq -0x10(%rbp), %rax
movzbl 0x4(%rax), %eax
movq 0x82312b(%rip), %rcx    # 0x831490
movzbl 0x4(%rcx), %ecx
subl %ecx, %eax
movb %al, %cl
movq 0x823124(%rip), %rax    # 0x831498
movb %cl, 0x9(%rax)
cmpq $0x0, 0x823111(%rip)    # 0x831490
je 0xe3a7
movq 0x823108(%rip), %rax    # 0x831490
movzbl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movzbl 0x8(%rcx), %ecx
cmpl %ecx, %eax
je 0xe3a7
leaq 0x8244cd(%rip), %rax    # 0x83286c
movzbl (%rax), %edi
callq 0xfa00
movq -0x10(%rbp), %rax
movq %rax, 0x8230de(%rip)    # 0x831490
movl $0x6, %edi
callq 0xd3d0
movq %rax, 0x81f57d(%rip)    # 0x82d940
movq %rax, 0x8230ce(%rip)    # 0x831498
movl $0xffffffff, 0x81f560(%rip) # imm = 0xFFFFFFFF
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)