// File: /workspace/github_cpp_makefile_star2_O2/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 0xfd53(%rip), %rax      # 0x1b470
shll $0x4, %edx
addq %rax, %rdx
addq $0x1000, %rdx           # imm = 0x1000
movl %esi, %r8d
shll $0x5, %r8d
xorl %r9d, %r9d
leaq 0xfd55(%rip), %r10      # 0x1b490
xorl %r11d, %r11d
cmpl $0x8, %r9d
je 0xb881
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)
movslq %r11d, %r11
xorl %ebx, %ebx
cmpl 0xfc41(%rip), %ebx      # 0x1b464
jge 0xb869
movq 0x813ad4(%rip), %r15    # 0x81f300
movslq 0x18(%r15), %r14
imulq %r11, %r14
addq 0x20(%r15), %r14
xorl %r15d, %r15d
cmpq $0x8, %r15
je 0xb862
xorl %r12d, %r12d
cmpl 0xfc15(%rip), %r12d     # 0x1b460
jge 0xb85a
movb (%rsp,%r15), %bpl
movb %bpl, (%r14,%r12)
incq %r12
jmp 0xb844
incq %r15
addq %r12, %r14
jmp 0xb83b
incl %ebx
incq %r11
jmp 0xb81d
addq $0x2, %rdx
movl $0x1010101, (%r8,%r10)  # imm = 0x1010101
addq $0x4, %r8
incl %r9d
jmp 0xb73e
movzbl %sil, %eax
movzbl %dil, %edx
imull 0xfbd0(%rip), %edx      # 0x1b460
shll $0x3, %edx
movq %rsp, %rcx
movl %edx, (%rcx)
imull 0xfbc5(%rip), %eax      # 0x1b464
shll $0x3, %eax
movl %eax, 0x4(%rcx)
movq 0x813a54(%rip), %rdi    # 0x81f300
movq 0x813a55(%rip), %rdx    # 0x81f308
xorl %esi, %esi
callq 0x6300
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq