// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/rf11.c
// Function: datox_rf11
static int
datox_rf11(Bus *bus, RF11 *rf, word mask)
{
	rf->bus = bus;
	RS11 *drive = &rf->drives[rf->d];
	if(bus->addr >= 0777460 && bus->addr < 0777500){
		switch(bus->addr&017){
		case 000:	// DCS
		case 001:
			SETMASK(rf->dcs, bus->data, mask&0176);
			if(bus->data & GO){
				// start function
				rf->done = 0;
				switch((rf->dcs>>1)&3){
				case FR_NOP:
					rf->dcs |= RDY;
					// ??? interrupt?
					break;
				case FR_READ:
				case FR_WRITE:
				case FR_WRITE_CHECK:
					rf->dcs &= ~RDY;
					if(drive->fp == nil)
						rferr(rf, NED);
					break;
				}
			}
			if(bus->data & DCLR)
				reset_rf11(rf);
			break;
		case 002:	// WC
		case 003:
			SETMASK(rf->wc, bus->data, mask);
			break;
		case 004:	// CMA
		case 005:
			SETMASK(rf->cma, bus->data, mask);
			break;
		case 006:	// DAR
		case 007:
			SETMASK(rf->dar, bus->data, mask);
			break;
		case 010:	// DAE
		case 011:
			SETMASK(rf->dae, bus->data, mask&0637);
			rf->dae &= ~DA14;
			seldisk(rf, (rf->dae>>2)&7);
			break;
		case 012:	// DBR
		case 013:
			SETMASK(rf->dbr, bus->data, mask);
			break;
		case 014:	// MA
		case 015:
			// not implemented
			break;
		case 016:	// ADS
		case 017:
			// read only
			break;
		default: assert(0);	/* can't happen */
		}
		return 0;
	}
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movw %dx, %ax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
addq $0x20, %rax
movq -0x18(%rbp), %rcx
movslq 0x1c(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x3ff30, 0x8(%rax)     # imm = 0x3FF30
jb 0x7c67
movq -0x10(%rbp), %rax
cmpl $0x3ff40, 0x8(%rax)     # imm = 0x3FF40
jae 0x7c67
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
andl $0xf, %eax
movl %eax, %ecx
movq %rcx, -0x30(%rbp)
subl $0xf, %eax
ja 0x7c3f
movq -0x30(%rbp), %rax
leaq 0x3c6d(%rip), %rcx      # 0xb6b0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movzwl 0x8(%rax), %eax
movzwl -0x1a(%rbp), %ecx
andl $0x7e, %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movzwl -0x1a(%rbp), %edx
andl $0x7e, %edx
andl %edx, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x7afa
movq -0x18(%rbp), %rax
movl $0x0, 0x18(%rax)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
andl $0x3, %eax
movl %eax, -0x34(%rbp)
je 0x7ab8
jmp 0x7aac
movl -0x34(%rbp), %eax
decl %eax
subl $0x3, %eax
jb 0x7acc
jmp 0x7af8
movq -0x18(%rbp), %rax
movzwl 0x8(%rax), %ecx
orl $0x80, %ecx
movw %cx, 0x8(%rax)
jmp 0x7af8
movq -0x18(%rbp), %rax
movzwl 0x8(%rax), %ecx
andl $0xffffff7f, %ecx       # imm = 0xFFFFFF7F
movw %cx, 0x8(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x7af6
movq -0x18(%rbp), %rdi
movl $0x800, %esi            # imm = 0x800
callq 0x84a0
jmp 0x7af8
jmp 0x7afa
movq -0x10(%rbp), %rax
movzwl 0xc(%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x0, %eax
je 0x7b15
movq -0x18(%rbp), %rdi
callq 0x8090
jmp 0x7c5e
movq -0x18(%rbp), %rax
movzwl 0xa(%rax), %eax
movzwl -0x1a(%rbp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movzwl -0x1a(%rbp), %edx
andl %edx, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xa(%rax)
jmp 0x7c5e
movq -0x18(%rbp), %rax
movzwl 0xc(%rax), %eax
movzwl -0x1a(%rbp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movzwl -0x1a(%rbp), %edx
andl %edx, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xc(%rax)
jmp 0x7c5e
movq -0x18(%rbp), %rax
movzwl 0xe(%rax), %eax
movzwl -0x1a(%rbp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movzwl -0x1a(%rbp), %edx
andl %edx, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0xe(%rax)
jmp 0x7c5e
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %eax
movzwl -0x1a(%rbp), %ecx
andl $0x19f, %ecx            # imm = 0x19F
xorl $-0x1, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movzwl -0x1a(%rbp), %edx
andl $0x19f, %edx            # imm = 0x19F
andl %edx, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x10(%rax)
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %ecx
andl $-0x21, %ecx
movw %cx, 0x10(%rax)
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movzwl 0x10(%rax), %esi
sarl $0x2, %esi
andl $0x7, %esi
callq 0x8110
jmp 0x7c5e
movq -0x18(%rbp), %rax
movzwl 0x12(%rax), %eax
movzwl -0x1a(%rbp), %ecx
xorl $-0x1, %ecx
andl %ecx, %eax
movq -0x10(%rbp), %rcx
movzwl 0xc(%rcx), %ecx
movzwl -0x1a(%rbp), %edx
andl %edx, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x18(%rbp), %rax
movw %cx, 0x12(%rax)
jmp 0x7c5e
jmp 0x7c5e
jmp 0x7c5e
leaq 0x37c5(%rip), %rdi      # 0xb40b
leaq 0x3aa3(%rip), %rsi      # 0xb6f0
movl $0xab, %edx
leaq 0x3ad5(%rip), %rcx      # 0xb72e
callq 0x20d0
movl $0x0, -0x4(%rbp)
jmp 0x7c6e
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)