// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/xgp.c
// Function: dato_xgp
int
dato_xgp(Bus *bus, void *dev)
{
	char file[256];
	XGP *xgp = dev;
	int offset, lines;
	word d;

	d = bus->data;
	switch(bus->addr){
	case XCR:
		if((d & FMOT) != 0 && xgp->speed == 0)
			fprintf(stderr, "Paper in motion\n");
		xgp->xcr = d;
		if((xgp->xcr & FMOT) != 0 && (xgp->xcr & FRDY) == 0)
			print_start();
		if(d & FGO) {
			if(xgp->xsr & FRDY) {
				xgp->xcr |= FGO;
				xgp->xcr &= ~FDONE;
				xgp->go = xgp_idle;
				xgp->mode = xgp_char;
				xgp->dots = 0;
			} else
				xgp->xcr |= FERR;
		}
		return 0;
	case MAR:
		xgp->mar = d;
		return 0;
	case XSR:
		xgp->xsr = d;
		return 0;
	case XCUT:
		if(bus->data & FCUTI) {
			offset = MKTOCT * 100000 / 60 / 775;
			lines = print_finish(offset, file, sizeof file);
			if(lines > 0 && *file != 0)
				fprintf(stderr, "Printed %d lines, %.1f inches to %s\n",
					lines, lines / 200.0, file);
			else if(lines < 0)
				fprintf(stderr, "Printing error\n");
			fprintf(stderr, "Paper cut\n");
		}
		return 0;
	}
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x140, %rsp            # imm = 0x140
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x10(%rbp), %rax
movw 0xc(%rax), %ax
movw %ax, -0x132(%rbp)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
addl $0xfffc0bc0, %eax       # imm = 0xFFFC0BC0
movl %eax, %ecx
movq %rcx, -0x140(%rbp)
subl $0x6, %eax
ja 0x3726
movq -0x140(%rbp), %rax
leaq 0x1ccaf(%rip), %rcx     # 0x201a8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movzwl -0x132(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x3538
movq -0x128(%rbp), %rax
cmpl $0x0, 0x44(%rax)
jne 0x3538
movq 0x25ad1(%rip), %rax     # 0x28ff8
movq (%rax), %rdi
leaq 0x1cccb(%rip), %rsi     # 0x201fc
movb $0x0, %al
callq 0x2140
movw -0x132(%rbp), %cx
movq -0x128(%rbp), %rax
movw %cx, 0x28(%rax)
movq -0x128(%rbp), %rax
movzwl 0x28(%rax), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0x3577
movq -0x128(%rbp), %rax
movzwl 0x28(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
jne 0x3577
callq 0x9490
movzwl -0x132(%rbp), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x360f
movq -0x128(%rbp), %rax
movzwl 0x2c(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x35f8
movq -0x128(%rbp), %rax
movzwl 0x28(%rax), %ecx
orl $0x1, %ecx
movw %cx, 0x28(%rax)
movq -0x128(%rbp), %rax
movzwl 0x28(%rax), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movw %cx, 0x28(%rax)
movq -0x128(%rbp), %rax
leaq -0x142(%rip), %rcx      # 0x3490
movq %rcx, 0x30(%rax)
movq -0x128(%rbp), %rax
leaq 0x15c(%rip), %rcx       # 0x3740
movq %rcx, 0x38(%rax)
movq -0x128(%rbp), %rax
movl $0x0, 0x48(%rax)
jmp 0x360d
movq -0x128(%rbp), %rax
movzwl 0x28(%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0x28(%rax)
jmp 0x360f
movl $0x0, -0x4(%rbp)
jmp 0x372d
movw -0x132(%rbp), %cx
movq -0x128(%rbp), %rax
movw %cx, 0x2a(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x372d
movw -0x132(%rbp), %cx
movq -0x128(%rbp), %rax
movw %cx, 0x2c(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x372d
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x371d
movl $0x1156, -0x12c(%rbp)   # imm = 0x1156
movl -0x12c(%rbp), %edi
leaq -0x120(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x9570
movl %eax, -0x130(%rbp)
cmpl $0x0, -0x130(%rbp)
jle 0x36e2
movsbl -0x120(%rbp), %eax
cmpl $0x0, %eax
je 0x36e2
movq 0x2594a(%rip), %rax     # 0x28ff8
movq (%rax), %rdi
movl -0x130(%rbp), %edx
cvtsi2sdl -0x130(%rbp), %xmm0
movsd 0x1cad9(%rip), %xmm1    # 0x201a0
divsd %xmm1, %xmm0
leaq -0x120(%rbp), %rcx
leaq 0x1cb34(%rip), %rsi     # 0x2020d
movb $0x1, %al
callq 0x2140
jmp 0x3705
cmpl $0x0, -0x130(%rbp)
jge 0x3703
movq 0x25906(%rip), %rax     # 0x28ff8
movq (%rax), %rdi
leaq 0x1cb36(%rip), %rsi     # 0x20232
movb $0x0, %al
callq 0x2140
jmp 0x3705
movq 0x258ec(%rip), %rax     # 0x28ff8
movq (%rax), %rdi
leaq 0x1cb2c(%rip), %rsi     # 0x20242
movb $0x0, %al
callq 0x2140
movl $0x0, -0x4(%rbp)
jmp 0x372d
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x140, %rsp            # imm = 0x140
popq %rbp
retq
nopl (%rax)