// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0xf4e0(%rip), %rax      # 0x1c460
shll $0x4, %edx
addq %rax, %rdx
addq $0x1000, %rdx           # imm = 0x1000
movl %esi, %r8d
shll $0x5, %r8d
xorl %r9d, %r9d
movl 0xf4b7(%rip), %ebx      # 0x1c454
leaq 0xf4dc(%rip), %r10      # 0x1c480
xorl %r11d, %r11d
movzbl (%rdx), %r14d
movl %r14d, %r15d
andl $0x3, %r15d
movzbl (%rcx,%r15), %r15d
movb 0xfe0(%rax,%r15), %bpl
movb %bpl, 0x8(%rsp)
movl %r14d, %r15d
shrl $0x2, %r15d
andl $0x3, %r15d
movzbl (%rcx,%r15), %r15d
movb 0xfe0(%rax,%r15), %bpl
movb %bpl, 0x9(%rsp)
movl %r14d, %r15d
shrl $0x4, %r15d
andl $0x3, %r15d
movzbl (%rcx,%r15), %r15d
movb 0xfe0(%rax,%r15), %bpl
movb %bpl, 0xa(%rsp)
shrl $0x6, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0xb(%rsp)
movzbl 0x1(%rdx), %r14d
movl %r14d, %r15d
andl $0x3, %r15d
movzbl (%rcx,%r15), %r15d
movb 0xfe0(%rax,%r15), %bpl
movb %bpl, 0xc(%rsp)
movl %r14d, %r15d
shrl $0x2, %r15d
andl $0x3, %r15d
movzbl (%rcx,%r15), %r15d
movb 0xfe0(%rax,%r15), %bpl
movb %bpl, 0xd(%rsp)
movl %r14d, %r15d
shrl $0x4, %r15d
andl $0x3, %r15d
movzbl (%rcx,%r15), %r15d
movb 0xfe0(%rax,%r15), %bpl
movb %bpl, 0xe(%rsp)
shrl $0x6, %r14d
movzbl (%rcx,%r14), %r14d
movb 0xfe0(%rax,%r14), %bpl
movb %bpl, 0xf(%rsp)
testl %ebx, %ebx
jle 0xd0e3
movslq %r9d, %r9
xorl %ebp, %ebp
movl 0xf3be(%rip), %r14d     # 0x1c450
movq 0x813257(%rip), %r15    # 0x8202f0
movslq 0x18(%r15), %rbx
imulq %r9, %rbx
addq 0x20(%r15), %rbx
xorl %r15d, %r15d
testl %r14d, %r14d
jle 0xd0cb
movb 0x8(%rsp,%r15), %r13b
xorl %r12d, %r12d
movb %r13b, (%rbx,%r12)
movl 0xf390(%rip), %r14d     # 0x1c450
incq %r12
cmpl %r14d, %r12d
jl 0xd0b5
addq %r12, %rbx
incq %r15
cmpq $0x8, %r15
jne 0xd0a8
incl %ebp
incq %r9
movl 0xf375(%rip), %ebx      # 0x1c454
cmpl %ebx, %ebp
jl 0xd092
addq $0x2, %rdx
movl $0x1010101, (%r8,%r10)  # imm = 0x1010101
addq $0x4, %r8
incl %r11d
cmpl $0x8, %r11d
jne 0xcfa7
movzbl %sil, %eax
movzbl %dil, %edx
imull 0xf341(%rip), %edx      # 0x1c450
shll $0x3, %edx
leaq 0x8(%rsp), %rcx
movl %edx, (%rcx)
imull %ebx, %eax
shll $0x3, %eax
movl %eax, 0x4(%rcx)
movq 0x8131c7(%rip), %rdi    # 0x8202f0
movq 0x8131c8(%rip), %rdx    # 0x8202f8
xorl %esi, %esi
callq 0x62e0
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq