// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/tv.c
// Function: handlemsg
static void
handlemsg(TV *tv, TVcon *con)
{
	uint16 len;
	uint8 *b;
	uint8 type;
	int x, y, w, h;

	if(readn(con->fd, &len, 2)){
err:
		closecon(tv, con);
		return;
	}
	len = b2w((uint8*)&len);

	b = largebuf;
	if(readn(con->fd, b, len))
		goto err;
	type = *b++;
	switch(type){
	case MSG_KEYDN:
		sendkey(tv, con->kbd, b2w(b));
		break;

	case MSG_GETFB:
		x = b2w(b);
		y = b2w(b+2);
		w = b2w(b+4);
		h = b2w(b+6);
		printf("getfb: %d %d %d %d\n", x, y, w, h);

		x /= 16;
		w = (w+15) / 16;
		b = largebuf;
		msgheader(b, MSG_FB, 1+8+w*h*2);
		b += 3;
		w2b(b, x);
		w2b(b+2, y);
		w2b(b+4, w);
		w2b(b+6, h);
		b += 8;
		packfb(tv, b, con->dpy, x, y, w, h);
		writen(con->fd, largebuf, 3+8+w*h*2);
		break;

	default:
		fprintf(stderr, "unknown msg type %d\n", type);
	}
	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
leaq -0x12(%rbp), %rsi
movl $0x2, %edx
callq 0xa650
cmpl $0x0, %eax
je 0x525d
jmp 0x524b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x51b0
jmp 0x545b
leaq -0x12(%rbp), %rdi
callq 0x4720
movw %ax, -0x12(%rbp)
leaq 0x8ff5f(%rip), %rax     # 0x951d0
movq %rax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl (%rax), %edi
movq -0x20(%rbp), %rsi
movzwl -0x12(%rbp), %edx
callq 0xa650
cmpl $0x0, %eax
je 0x528f
jmp 0x524b
movq -0x20(%rbp), %rax
movq %rax, %rcx
incq %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %al
movb %al, -0x21(%rbp)
movzbl -0x21(%rbp), %eax
movl %eax, -0x38(%rbp)
testl %eax, %eax
je 0x52bc
jmp 0x52af
movl -0x38(%rbp), %eax
subl $0x1, %eax
je 0x52f0
jmp 0x543f
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movw %ax, -0x3a(%rbp)
movq -0x20(%rbp), %rdi
callq 0x4720
movq -0x48(%rbp), %rdi
movw -0x3a(%rbp), %cx
movzwl %cx, %esi
movzwl %ax, %edx
callq 0x5470
jmp 0x545b
movq -0x20(%rbp), %rdi
callq 0x4720
movzwl %ax, %eax
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
addq $0x2, %rdi
callq 0x4720
movzwl %ax, %eax
movl %eax, -0x2c(%rbp)
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
callq 0x4720
movzwl %ax, %eax
movl %eax, -0x30(%rbp)
movq -0x20(%rbp), %rdi
addq $0x6, %rdi
callq 0x4720
movzwl %ax, %eax
movl %eax, -0x34(%rbp)
movl -0x28(%rbp), %esi
movl -0x2c(%rbp), %edx
movl -0x30(%rbp), %ecx
movl -0x34(%rbp), %r8d
leaq 0x5fcc(%rip), %rdi      # 0xb318
movb $0x0, %al
callq 0x20f0
movl -0x28(%rbp), %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, -0x28(%rbp)
movl -0x30(%rbp), %eax
addl $0xf, %eax
movl $0x10, %ecx
cltd
idivl %ecx
movl %eax, -0x30(%rbp)
leaq 0x8fe57(%rip), %rax     # 0x951d0
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl -0x30(%rbp), %eax
imull -0x34(%rbp), %eax
shll %eax
addl $0x9, %eax
movl $0x2, %esi
movzwl %ax, %edx
callq 0x4770
movq -0x20(%rbp), %rax
addq $0x3, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl -0x28(%rbp), %eax
movzwl %ax, %esi
callq 0x4740
movq -0x20(%rbp), %rdi
addq $0x2, %rdi
movl -0x2c(%rbp), %eax
movzwl %ax, %esi
callq 0x4740
movq -0x20(%rbp), %rdi
addq $0x4, %rdi
movl -0x30(%rbp), %eax
movzwl %ax, %esi
callq 0x4740
movq -0x20(%rbp), %rdi
addq $0x6, %rdi
movl -0x34(%rbp), %eax
movzwl %ax, %esi
callq 0x4740
movq -0x20(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x10(%rbp), %rax
movl 0x4(%rax), %edx
movl -0x28(%rbp), %ecx
movl -0x2c(%rbp), %r8d
movl -0x30(%rbp), %r9d
movl -0x34(%rbp), %eax
movl %eax, (%rsp)
callq 0x4810
movq -0x10(%rbp), %rax
movl (%rax), %edi
movl -0x30(%rbp), %edx
imull -0x34(%rbp), %edx
shll %edx
addl $0xb, %edx
leaq 0x8fd98(%rip), %rsi     # 0x951d0
callq 0xa6c0
jmp 0x545b
movq 0x8bb2(%rip), %rax      # 0xdff8
movq (%rax), %rdi
movzbl -0x21(%rbp), %edx
leaq 0x5ed8(%rip), %rsi      # 0xb32c
movb $0x0, %al
callq 0x2190
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)