// File: /workspace/github_c_makefile_star2_O0/aap[P]rx-0/tx0/mach.c
// Function: handleio
void
handleio(TX0 *tx)
{
	int c;

	if(tx->fl->dly == 0){
		if(hasinput(tx->fl->in)){
			c = getfl(tx->fl);
			tx->lr = 0400000;
	// this is correct:
			tx->lr |= (c&077) << 11;
	// this is not:
	//if(c & 001) tx->lr |= 0000001;
	//if(c & 002) tx->lr |= 0000010;
	//if(c & 004) tx->lr |= 0000100;
	//if(c & 010) tx->lr |= 0001000;
	//if(c & 020) tx->lr |= 0010000;
	//if(c & 040) tx->lr |= 0100000;
		}
		// don't wanna poll this all the time
		// around 16cps max
		tx->fl->dly = 10000;
	}else
		tx->fl->dly--;
	if(tx->fl_printing){
		c = 0;
		if(tx->ac & 0000001) c |= 1;
		if(tx->ac & 0000010) c |= 2;
		if(tx->ac & 0000100) c |= 4;
		if(tx->ac & 0001000) c |= 010;
		if(tx->ac & 0010000) c |= 020;
		if(tx->ac & 0100000) c |= 040;
		putfl(tx->fl, c);
		tx->fl_printing = 0;
		iorestart(tx);
	}
	if(tx->displaying){
		if(tx->scope_fd >= 0){
			u32 cmd = 0;
			int x = (tx->ac>>9)&0777;
			int y = tx->ac&0777;
			// Convert [-1.0,+1.0] to [0,1023]
			if(x & 0400) x++;
			if(y & 0400) y++;
			x += 0400;
			y += 0400;
			x &= 0777;
			y &= 0777;
			x <<= 1;
			y <<= 1;
			cmd = x;
			cmd |= y<<10;
			cmd |= 7<<20;
			write(tx->scope_fd, &cmd, 4);
//	usleep(1000);
		}
		tx->displaying = 0;
		iorestart(tx);
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq 0x40040(%rax), %rax
cmpl $0x0, 0x8(%rax)
jne 0x4df9
movq -0x8(%rbp), %rax
movq 0x40040(%rax), %rax
movl (%rax), %edi
callq 0x3960
cmpl $0x0, %eax
je 0x4de5
movq -0x8(%rbp), %rax
movq 0x40040(%rax), %rdi
callq 0x4d40
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl $0x20000, 0x14(%rax)    # imm = 0x20000
movl -0xc(%rbp), %ecx
andl $0x3f, %ecx
shll $0xb, %ecx
movq -0x8(%rbp), %rax
orl 0x14(%rax), %ecx
movl %ecx, 0x14(%rax)
movq -0x8(%rbp), %rax
movq 0x40040(%rax), %rax
movl $0x2710, 0x8(%rax)      # imm = 0x2710
jmp 0x4e0d
movq -0x8(%rbp), %rax
movq 0x40040(%rax), %rax
movl 0x8(%rax), %ecx
addl $-0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
cmpl $0x0, 0x40048(%rax)
je 0x4ee5
movl $0x0, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4e3d
movl -0xc(%rbp), %eax
orl $0x1, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x4e55
movl -0xc(%rbp), %eax
orl $0x2, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x4e6d
movl -0xc(%rbp), %eax
orl $0x4, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x200, %eax            # imm = 0x200
cmpl $0x0, %eax
je 0x4e87
movl -0xc(%rbp), %eax
orl $0x8, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0x4ea1
movl -0xc(%rbp), %eax
orl $0x10, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x8000, %eax           # imm = 0x8000
cmpl $0x0, %eax
je 0x4ebb
movl -0xc(%rbp), %eax
orl $0x20, %eax
movl %eax, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq 0x40040(%rax), %rdi
movl -0xc(%rbp), %esi
callq 0x4d00
movq -0x8(%rbp), %rax
movl $0x0, 0x40048(%rax)
movq -0x8(%rbp), %rdi
callq 0x4ff0
movq -0x8(%rbp), %rax
cmpl $0x0, 0x4004c(%rax)
je 0x4fe3
movq -0x8(%rbp), %rax
cmpl $0x0, 0x40050(%rax)
jl 0x4fcc
movl $0x0, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
shrl $0x9, %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x14(%rbp)
movq -0x8(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x4f45
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x4f5b
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
shll %eax
movl %eax, -0x14(%rbp)
movl -0x18(%rbp), %eax
shll %eax
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x18(%rbp), %eax
shll $0xa, %eax
orl -0x10(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0x10(%rbp), %eax
orl $0x700000, %eax         # imm = 0x700000
movl %eax, -0x10(%rbp)
movq -0x8(%rbp), %rax
movl 0x40050(%rax), %edi
leaq -0x10(%rbp), %rsi
movl $0x4, %edx
callq 0x20b0
movq -0x8(%rbp), %rax
movl $0x0, 0x4004c(%rax)
movq -0x8(%rbp), %rdi
callq 0x4ff0
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax)