// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/rf11.c
// Function: svc_rs11
void
svc_rs11(RS11 *drive, RF11 *rf, int selected)
{
	if(drive->fp == nil){
		drive->ads = 0;
		return;
	}

	// read/write data
	if(selected && (rf->dcs&RDY)==0){
		// track address we want
		seltrack(rf, (rf->dar>>11) | (rf->dae&3)<<5);

		// word we're interested in
		if(rf->wc && drive->ads == (rf->dar&03777)){
			// read/write word here
			switch((rf->dcs>>1)&3){
			case FR_READ:
				rf->dbr = WD(rf->buf[drive->ads*2+1], rf->buf[drive->ads*2]);

				// write to bus
				rf->bus->data = rf->dbr;
				rf->bus->addr = busaddr(rf);
				if(dato_bus(rf->bus))
					rferr(rf, NEM);
				break;
			case FR_WRITE:
			case FR_WRITE_CHECK:
				// read from bus
				rf->bus->addr = busaddr(rf);
				if(dati_bus(rf->bus))
					rferr(rf, NEM);
				rf->dbr = rf->bus->data;

				rf->buf[drive->ads*2] = rf->dbr;
				rf->buf[drive->ads*2+1] = rf->dbr>>8;
				rf->dirty = 1;
				break;
			}

			rf->wc++;
			if(rf->wc == 0){
				rf->dcs |= RDY;
				rf->done = 1;
			}else{
				// count
				rf->dar++;
				if(rf->dar == 0){
					// carry into dae
					rf->dae++;
					// this can carry into disk address
					seldisk(rf, (rf->dae>>2)&017);
				}
			}
		}
	}

	// rotate - one word every 16us
	// address of next word on track
	drive->ads = (drive->ads+1)&03777;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movq -0x8(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x7ddc
movq -0x8(%rbp), %rax
movw $0x0, 0x8(%rax)
jmp 0x8055
cmpl $0x0, -0x14(%rbp)
je 0x803a
movq -0x10(%rbp), %rax
movzwl 0x8(%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
jne 0x803a
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %esi
sarl $0xb, %esi
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %eax
andl $0x3, %eax
shll $0x5, %eax
orl %eax, %esi
callq 0x8310
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %eax
cmpl $0x0, %eax
je 0x8038
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
movq -0x10(%rbp), %rcx
movzwl 0xe(%rcx), %ecx
andl $0x7ff, %ecx            # imm = 0x7FF
cmpl %ecx, %eax
jne 0x8038
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
shrl %eax
andl $0x3, %eax
movl %eax, -0x18(%rbp)
subl $0x1, %eax
je 0x7f15
jmp 0x7e69
movl -0x18(%rbp), %eax
subl $0x2, %eax
je 0x7e84
jmp 0x7e73
movl -0x18(%rbp), %eax
subl $0x3, %eax
je 0x7f15
jmp 0x7fb4
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
shll %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movzbl 0xa8(%rax,%rcx), %eax
shll $0x8, %eax
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rdx
movzwl 0x8(%rdx), %edx
shll %edx
movslq %edx, %rdx
movzbl 0xa8(%rcx,%rdx), %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0x10(%rbp), %rax
movw 0x12(%rax), %cx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movw %cx, 0xc(%rax)
movq -0x10(%rbp), %rdi
callq 0x8420
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x2410
cmpl $0x0, %eax
je 0x7f10
movq -0x10(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x84a0
jmp 0x7fb4
movq -0x10(%rbp), %rdi
callq 0x8420
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
callq 0x23a0
cmpl $0x0, %eax
je 0x7f49
movq -0x10(%rbp), %rdi
movl $0x400, %esi            # imm = 0x400
callq 0x84a0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movw 0xc(%rax), %cx
movq -0x10(%rbp), %rax
movw %cx, 0x12(%rax)
movq -0x10(%rbp), %rax
movw 0x12(%rax), %ax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
shll %ecx
movslq %ecx, %rcx
movb %dl, 0xa8(%rax,%rcx)
movq -0x10(%rbp), %rax
movzwl 0x12(%rax), %eax
sarl $0x8, %eax
movb %al, %dl
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rcx
movzwl 0x8(%rcx), %ecx
shll %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movb %dl, 0xa8(%rax,%rcx)
movq -0x10(%rbp), %rax
movl $0x1, 0xa0(%rax)
movq -0x10(%rbp), %rax
movw 0xa(%rax), %cx
addw $0x1, %cx
movw %cx, 0xa(%rax)
movq -0x10(%rbp), %rax
movzwl 0xa(%rax), %eax
cmpl $0x0, %eax
jne 0x7ff0
movq -0x10(%rbp), %rax
movzwl 0x8(%rax), %ecx
orl $0x80, %ecx
movw %cx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x18(%rax)
jmp 0x8036
movq -0x10(%rbp), %rax
movw 0xe(%rax), %cx
addw $0x1, %cx
movw %cx, 0xe(%rax)
movq -0x10(%rbp), %rax
movzwl 0xe(%rax), %eax
cmpl $0x0, %eax
jne 0x8034
movq -0x10(%rbp), %rax
movw 0x10(%rax), %cx
addw $0x1, %cx
movw %cx, 0x10(%rax)
movq -0x10(%rbp), %rdi
movq -0x10(%rbp), %rax
movzwl 0x10(%rax), %esi
sarl $0x2, %esi
andl $0xf, %esi
callq 0x8110
jmp 0x8036
jmp 0x8038
jmp 0x803a
movq -0x8(%rbp), %rax
movzwl 0x8(%rax), %eax
addl $0x1, %eax
andl $0x7ff, %eax            # imm = 0x7FF
movw %ax, %cx
movq -0x8(%rbp), %rax
movw %cx, 0x8(%rax)
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)