// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/kd11b.c
// Function: dati
int
dati(KD11B *cpu, int b, int pse)
{
trace("dati %06o: ", cpu->ba);
	if(cpu->bus->pause)
		printf("XXXX: DATIP not ended properly\n");
	cpu->bus->pause = pse;

	/* allow odd addresses for bytes and registers */
	int alodd = b || cpu->ba >= 0177700 && cpu->ba < 0177720;

	if(!alodd && cpu->ba&1)
		goto be;

	/* internal registers */
	if((cpu->ba&0177400) == 0177400){
		if((cpu->ba&0360) == 0300){
			cpu->bus->data = cpu->r[cpu->ba&017];
			goto ok;
		}
		switch(cpu->ba&0377){
		/* Line clock */
		case 0146:
			cpu->bus->data = cpu->lc_int_enab<<6 |
				cpu->lc_clock<<7;
			goto ok;
		/* Receive */
		case 0160:
			cpu->bus->data = cpu->rcd_int_enab<<6 |
				cpu->rcd_da<<7 |
				cpu->rcd_busy<<11;
			goto ok;
		case 0162:
			cpu->bus->data = cpu->rcd_b;
			cpu->rcd_b = 0;
			cpu->rcd_da = 0;
			cpu->rcd_int = 0;
			goto ok;
		/* Transmit */
		case 0164:
			cpu->bus->data = cpu->xmit_maint<<2 |
				cpu->xmit_int_enab<<6 |
				cpu->xmit_tbmt<<7;
			goto ok;
		case 0166:
			/* write only */
			cpu->bus->data = 0;
			goto ok;
		case 0170: case 0171:
			cpu->bus->data = cpu->sw;
			goto ok;
		case 0376: case 0377:
			cpu->bus->data = cpu->psw;
			goto ok;

		/* respond but don't return real data */
		case 0147:
		case 0161:
		case 0163:
		case 0165:
		case 0167:
			cpu->bus->data = 0;
			goto ok;
		}
	}

	cpu->bus->addr = ubxt(cpu->ba)&~1;
	if(dati_bus(cpu->bus))
		goto be;
ok:
	trace("%06o\n", cpu->bus->data);
	cpu->be = 0;
	return 0;
be:
	trace("BE\n");
	cpu->bus->pause = 0;
	cpu->be++;
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
cmpl $0x0, 0x10(%rax)
je 0x1ede
leaq 0x5326(%rip), %rdi      # 0x71fd
movb $0x0, %al
callq 0x10a0
movl -0x18(%rbp), %ecx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %ecx, 0x10(%rax)
movb $0x1, %al
cmpl $0x0, -0x14(%rbp)
movb %al, -0x1d(%rbp)
jne 0x1f25
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %ecx
xorl %eax, %eax
cmpl $0xffc0, %ecx           # imm = 0xFFC0
movb %al, -0x1e(%rbp)
jl 0x1f1f
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %eax
cmpl $0xffd0, %eax           # imm = 0xFFD0
setl %al
movb %al, -0x1e(%rbp)
movb -0x1e(%rbp), %al
movb %al, -0x1d(%rbp)
movb -0x1d(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x1f4b
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x1f4b
jmp 0x21e8
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %eax
andl $0xff00, %eax           # imm = 0xFF00
cmpl $0xff00, %eax           # imm = 0xFF00
jne 0x21a1
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %eax
andl $0xf0, %eax
cmpl $0xc0, %eax
jne 0x1f9e
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rcx
movzwl 0x22(%rcx), %ecx
andl $0xf, %ecx
movslq %ecx, %rcx
movw (%rax,%rcx,2), %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movzbl 0x22(%rax), %eax
movl %eax, -0x24(%rbp)
subl $0x66, %eax
je 0x2059
jmp 0x1fb4
movl -0x24(%rbp), %eax
subl $0x67, %eax
je 0x218f
jmp 0x1fc2
movl -0x24(%rbp), %eax
subl $0x70, %eax
je 0x2089
jmp 0x1fd0
movl -0x24(%rbp), %eax
subl $0x71, %eax
je 0x218f
jmp 0x1fde
movl -0x24(%rbp), %eax
subl $0x72, %eax
je 0x20c8
jmp 0x1fec
movl -0x24(%rbp), %eax
subl $0x73, %eax
je 0x218f
jmp 0x1ffa
movl -0x24(%rbp), %eax
subl $0x74, %eax
je 0x210e
jmp 0x2008
movl -0x24(%rbp), %eax
subl $0x75, %eax
je 0x218f
jmp 0x2016
movl -0x24(%rbp), %eax
subl $0x76, %eax
je 0x214d
jmp 0x2024
movl -0x24(%rbp), %eax
subl $0x77, %eax
je 0x218f
jmp 0x2032
movl -0x24(%rbp), %eax
addl $-0x78, %eax
subl $0x2, %eax
jb 0x215d
jmp 0x2043
movl -0x24(%rbp), %eax
addl $0xffffff02, %eax       # imm = 0xFFFFFF02
subl $0x2, %eax
jb 0x2176
jmp 0x219f
movq -0x10(%rbp), %rax
movl 0x84(%rax), %eax
shll $0x6, %eax
movq -0x10(%rbp), %rcx
movl 0x88(%rcx), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movl 0x98(%rax), %eax
shll $0x6, %eax
movq -0x10(%rbp), %rcx
movl 0xa0(%rcx), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movl 0x90(%rcx), %ecx
shll $0xb, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movzbl 0xa4(%rax), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
movq -0x10(%rbp), %rax
movb $0x0, 0xa4(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0xa0(%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x9c(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movl 0xac(%rax), %eax
shll $0x2, %eax
movq -0x10(%rbp), %rcx
movl 0xa8(%rcx), %ecx
shll $0x6, %ecx
orl %ecx, %eax
movq -0x10(%rbp), %rcx
movl 0xb4(%rcx), %ecx
shll $0x7, %ecx
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw $0x0, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movw 0x80(%rax), %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movzbl 0x30(%rax), %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw %cx, 0xc(%rax)
jmp 0x21d4
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movw $0x0, 0xc(%rax)
jmp 0x21d4
jmp 0x21a1
movq -0x10(%rbp), %rax
movzwl 0x22(%rax), %edi
callq 0x2220
movl %eax, %ecx
andl $-0x2, %ecx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x1380
cmpl $0x0, %eax
je 0x21d2
jmp 0x21e8
jmp 0x21d4
movq -0x10(%rbp), %rax
movl $0x0, 0x38(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x220b
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)