// File: /workspace/github_c_makefile_star2_O0/aap[P]rx-0/ww1/mach.c
// Function: handleio
void
handleio(WWI *ww)
{
	if(ww->active_unit && ww->active_unit->active){
		if(ww->ioc_out)
			ww->active_unit->record(ww, ww->active_unit);
		else
			ww->active_unit->read(ww, ww->active_unit);
	}

	if(ww->scope->fd >= 0 && hasinput(ww->scope->fd)){
		u32 input;
		if(readn(ww->scope->fd, &input, 4) < 0){
			ww->scope->fd = -1;
			return;
		}
		if(input & 0x80000000){
			// light pen/gun
			ww->scope->gunx = input & 01777;
			ww->scope->guny = (input>>10) & 01777;
			ww->scope->gun = (input>>20) & 1;
		}else{
			int id = input>>24;
			// we'll use FF register 2 for the input bits
			if(id == 0){
				ww->ffs[2] &= ~0140000;	// need upper 2 bits
				if(input & 0200) ww->ffs[2] |= 0100000;	// up
				if(input & 0100) ww->ffs[2] |= 0040000;	// down
			}else{
				ww->ffs[2] &= ~0030000;	// need next 2 bits
				if(input & 0200) ww->ffs[2] |= 0020000;	// up
				if(input & 0100) ww->ffs[2] |= 0010000;	// down
			}
		}
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x10, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10d0(%rax)
je 0x58eb
movq -0x8(%rbp), %rax
movq 0x10d0(%rax), %rax
cmpl $0x0, (%rax)
je 0x58eb
movq -0x8(%rbp), %rax
cmpl $0x0, 0x10bc(%rax)
je 0x58c9
movq -0x8(%rbp), %rax
movq 0x10d0(%rax), %rax
movq 0x18(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rcx
movq 0x10d0(%rcx), %rsi
callq *%rax
jmp 0x58e9
movq -0x8(%rbp), %rax
movq 0x10d0(%rax), %rax
movq 0x20(%rax), %rax
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rcx
movq 0x10d0(%rcx), %rsi
callq *%rax
jmp 0x58eb
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
cmpl $0x0, 0x28(%rax)
jl 0x5a61
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
movl 0x28(%rax), %edi
callq 0x3970
cmpl $0x0, %eax
je 0x5a61
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
movl 0x28(%rax), %edi
leaq -0xc(%rbp), %rsi
movl $0x4, %edx
callq 0x3ae0
cmpl $0x0, %eax
jge 0x5954
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
movl $0xffffffff, 0x28(%rax) # imm = 0xFFFFFFFF
jmp 0x5a61
movl -0xc(%rbp), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x59ae
movl -0xc(%rbp), %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
movl %ecx, 0x30(%rax)
movl -0xc(%rbp), %ecx
shrl $0xa, %ecx
andl $0x3ff, %ecx            # imm = 0x3FF
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
movl %ecx, 0x34(%rax)
movl -0xc(%rbp), %ecx
shrl $0x14, %ecx
andl $0x1, %ecx
movq -0x8(%rbp), %rax
movq 0x10e0(%rax), %rax
movl %ecx, 0x2c(%rax)
jmp 0x5a5f
movl -0xc(%rbp), %eax
shrl $0x18, %eax
movl %eax, -0x10(%rbp)
cmpl $0x0, -0x10(%rbp)
jne 0x5a0d
movq -0x8(%rbp), %rax
movzwl 0x20(%rax), %ecx
andl $0xffff3fff, %ecx       # imm = 0xFFFF3FFF
movw %cx, 0x20(%rax)
movl -0xc(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x59ee
movq -0x8(%rbp), %rax
movzwl 0x20(%rax), %ecx
orl $0x8000, %ecx           # imm = 0x8000
movw %cx, 0x20(%rax)
movl -0xc(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x5a0b
movq -0x8(%rbp), %rax
movzwl 0x20(%rax), %ecx
orl $0x4000, %ecx           # imm = 0x4000
movw %cx, 0x20(%rax)
jmp 0x5a5d
movq -0x8(%rbp), %rax
movzwl 0x20(%rax), %ecx
andl $0xffffcfff, %ecx       # imm = 0xFFFFCFFF
movw %cx, 0x20(%rax)
movl -0xc(%rbp), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0x5a3e
movq -0x8(%rbp), %rax
movzwl 0x20(%rax), %ecx
orl $0x2000, %ecx           # imm = 0x2000
movw %cx, 0x20(%rax)
movl -0xc(%rbp), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x5a5b
movq -0x8(%rbp), %rax
movzwl 0x20(%rax), %ecx
orl $0x1000, %ecx           # imm = 0x1000
movw %cx, 0x20(%rax)
jmp 0x5a5d
jmp 0x5a5f
jmp 0x5a61
addq $0x10, %rsp
popq %rbp
retq
nopw (%rax,%rax)