// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/tv.c
// Function: packfb
static void
packfb(TV *tv, uint8 *dst, int osw, int x, int y, int w, int h)
{
	int stride;
	int n1, n2;
	word *src1, *src2;
	word bw1, bw2;

	stride = WIDTH/16;

	/* We mix the outputs of both sections for the final output.
	 * This feature does not seem to be used by the TV system
	 * but it's theoretically capable of doing something like this.
	 * External video input is not supported here of course. */
	n1 = dpymap[0][tv->vswsect[0][osw]];
	n2 = dpymap[1][tv->vswsect[1][osw]];
//printf("inbuf: %d %d\n", n1, n2);
	src1 = n1 < 0 ? nullfb : &tv->buffers[n1].fb[stride*y + x];
	src2 = n2 < 0 ? nullfb : &tv->buffers[n2].fb[stride*y + x];
	bw1 = n1 < 0 ? 0 : tv->buffers[n1].mask;
	bw2 = n2 < 0 ? 0 : tv->buffers[n2].mask;
	for(y = 0; y < h; y++){
		for(x = 0; x < w; x++){
			/* We mix with an OR */
			w2b(dst, src1[x]^bw1 | src2[x]^bw2);
			dst += 2;
		}
		src1 += stride;
		src2 += stride;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movl $0x24, -0x24(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movzbl 0x8088c(%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x9b1f(%rip), %rax      # 0xe370
movl (%rax,%rcx,4), %eax
movl %eax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movslq -0x14(%rbp), %rcx
movzbl 0x808ac(%rax,%rcx), %eax
movl %eax, %ecx
leaq 0x9b00(%rip), %rax      # 0xe370
movl 0x40(%rax,%rcx,4), %eax
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x488a
leaq 0xa094c(%rip), %rax     # 0xa51d0
movq %rax, -0x50(%rbp)
jmp 0x48b7
movq -0x8(%rbp), %rax
addq $0x8, %rax
movslq -0x28(%rbp), %rcx
imulq $0x8088, %rcx, %rcx     # imm = 0x8088
addq %rcx, %rax
movl -0x24(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x38(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x48d2
leaq 0xa0904(%rip), %rax     # 0xa51d0
movq %rax, -0x58(%rbp)
jmp 0x48ff
movq -0x8(%rbp), %rax
addq $0x8, %rax
movslq -0x2c(%rbp), %rcx
imulq $0x8088, %rcx, %rcx     # imm = 0x8088
addq %rcx, %rax
movl -0x24(%rbp), %ecx
imull -0x1c(%rbp), %ecx
addl -0x18(%rbp), %ecx
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0x4914
xorl %eax, %eax
movl %eax, -0x5c(%rbp)
jmp 0x4934
movq -0x8(%rbp), %rax
addq $0x8, %rax
movslq -0x28(%rbp), %rcx
imulq $0x8088, %rcx, %rcx     # imm = 0x8088
addq %rcx, %rax
movzwl 0x8000(%rax), %eax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movw %ax, -0x42(%rbp)
cmpl $0x0, -0x2c(%rbp)
jge 0x4948
xorl %eax, %eax
movl %eax, -0x60(%rbp)
jmp 0x4968
movq -0x8(%rbp), %rax
addq $0x8, %rax
movslq -0x2c(%rbp), %rcx
imulq $0x8088, %rcx, %rcx     # imm = 0x8088
addq %rcx, %rax
movzwl 0x8000(%rax), %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %eax
movw %ax, -0x44(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl 0x10(%rbp), %eax
jge 0x4a10
movl $0x0, -0x18(%rbp)
movl -0x18(%rbp), %eax
cmpl -0x20(%rbp), %eax
jge 0x49da
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movslq -0x18(%rbp), %rcx
movzwl (%rax,%rcx,2), %eax
movzwl -0x42(%rbp), %ecx
xorl %ecx, %eax
movq -0x40(%rbp), %rcx
movslq -0x18(%rbp), %rdx
movzwl (%rcx,%rdx,2), %ecx
movzwl -0x44(%rbp), %edx
xorl %edx, %ecx
orl %ecx, %eax
movzwl %ax, %esi
callq 0x4740
movq -0x10(%rbp), %rax
addq $0x2, %rax
movq %rax, -0x10(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x4989
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movl -0x24(%rbp), %ecx
movq -0x40(%rbp), %rax
movslq %ecx, %rcx
shlq %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x4976
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)