// File: /workspace/github_cpp_makefile_star2_O1/mdpkh[P]retro6k/src/main.cpp
// Function: PaintCell(unsigned char, unsigned char, unsigned char, unsigned char*)
void PaintCell(unsigned char col, unsigned char row, unsigned char glyph, unsigned char* att)
{
	unsigned char* faddr = sysram;
	faddr += 0x1000 | (glyph << 4);
	unsigned char* paddr = sysram;
	paddr += 0x0FE0;
	for (int gy = 0, cy = 0, sy = row << 5; gy < 8; ++gy)
	{
		unsigned char pix[8];
		pix[0] = paddr[att[(*faddr & 0x3)]];
		pix[1] = paddr[att[(*faddr & 0xC) >> 2]];
		pix[2] = paddr[att[(*faddr & 0x30) >> 4]];
		pix[3] = paddr[att[(*faddr & 0xC0) >> 6]];
		faddr++;
		pix[4] = paddr[att[(*faddr & 0x3)]];
		pix[5] = paddr[att[(*faddr & 0xC) >> 2]];
		pix[6] = paddr[att[(*faddr & 0x30) >> 4]];
		pix[7] = paddr[att[(*faddr & 0xC0) >> 6]];
		faddr++;
		for (int ry = 0; ry < config.screen.pixheight; ++ry, ++cy)
		{
			unsigned char* dst = (unsigned char*)cellcanvas->pixels + (long long)cellcanvas->pitch * cy;
			for (int gx = 0, cx = 0; gx < 8; ++gx)
			{
				for (int rx = 0; rx < config.screen.pixwidth; ++rx, ++dst)
				{
					*dst = pix[gx];
				}
			}
		}
		scanlinedirty[sy++] = true;
		scanlinedirty[sy++] = true;
		scanlinedirty[sy++] = true;
		scanlinedirty[sy++] = true;
	}
	SDL_Rect dstrect;
	dstrect.x = col * config.screen.pixwidth * 8;
	dstrect.y = row * config.screen.pixheight * 8;
	SDL_BlitSurface(cellcanvas, nullptr, framebuffer, &dstrect);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
movq 0xfadd(%rip), %rax      # 0x1c460
shll $0x4, %edx
addq %rax, %rdx
addq $0x1000, %rdx           # imm = 0x1000
movl %esi, %r8d
shll $0x5, %r8d
xorl %r9d, %r9d
leaq 0xfadf(%rip), %r10      # 0x1c480
xorl %r11d, %r11d
movzbl (%rdx), %ebx
movl %ebx, %r14d
andl $0x3, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, (%rsp)
movl %ebx, %r14d
shrl $0x2, %r14d
andl $0x3, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0x1(%rsp)
movl %ebx, %r14d
shrl $0x4, %r14d
andl $0x3, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0x2(%rsp)
shrl $0x6, %ebx
movzbl (%rcx,%rbx), %ebx
movb 0xfe0(%rax,%rbx), %bl
movb %bl, 0x3(%rsp)
movzbl 0x1(%rdx), %ebx
movl %ebx, %r14d
andl $0x3, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0x4(%rsp)
movl %ebx, %r14d
shrl $0x2, %r14d
andl $0x3, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0x5(%rsp)
movl %ebx, %r14d
shrl $0x4, %r14d
andl $0x3, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0x6(%rsp)
shrl $0x6, %ebx
movzbl (%rcx,%rbx), %ebx
movb 0xfe0(%rax,%rbx), %bl
movb %bl, 0x7(%rsp)
cmpl $0x0, 0xf9d9(%rip)      # 0x1c454
jle 0xcad1
movslq %r9d, %r9
xorl %ebx, %ebx
movq 0x813867(%rip), %r15    # 0x8202f0
movslq 0x18(%r15), %r14
imulq %r9, %r14
addq 0x20(%r15), %r14
xorl %r15d, %r15d
cmpl $0x0, 0xf9b1(%rip)      # 0x1c450
jle 0xcabb
xorl %r12d, %r12d
movb (%rsp,%r15), %bpl
movb %bpl, (%r14,%r12)
incq %r12
cmpl 0xf99a(%rip), %r12d     # 0x1c450
jl 0xcaa4
addq %r12, %r14
incq %r15
cmpq $0x8, %r15
jne 0xca98
incl %ebx
incq %r9
cmpl 0xf985(%rip), %ebx      # 0x1c454
jl 0xca82
addq $0x2, %rdx
movl $0x1010101, (%r8,%r10)  # imm = 0x1010101
addq $0x4, %r8
incl %r11d
cmpl $0x8, %r11d
jne 0xc9a4
movzbl %sil, %eax
movzbl %dil, %edx
imull 0xf953(%rip), %edx      # 0x1c450
shll $0x3, %edx
movq %rsp, %rcx
movl %edx, (%rcx)
imull 0xf948(%rip), %eax      # 0x1c454
shll $0x3, %eax
movl %eax, 0x4(%rcx)
movq 0x8137d7(%rip), %rdi    # 0x8202f0
movq 0x8137d8(%rip), %rdx    # 0x8202f8
xorl %esi, %esi
callq 0x62e0
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq