// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kd11a.c
// Function: fetch_dst
static int
fetch_dst(KD11A *cpu, int m, int b, int pse)
{
	int dm, df;
	int ai;

	df = m&7;
	dm = m>>3;
	if(df == SP && USER) df = USP;	// KT11-SP
	ai = 1 + (!b || (df&6)==6 || dm&1);
	switch(dm){
	case 0:
		assert(0);	// we don't do that here
		break;
	case 1:
		// DST00
		setBA(cpu, R[df], df, pse, !b);
		setMM(cpu, 1);
		goto DST14;
	case 2:
		// DST01
		setBA(cpu, R[df], df, pse, !b);
		setMM(cpu, 1);
		D = R[df] + ai;
		goto DST03;
	case 3:
		// DST04
		setBA(cpu, R[df], df, 0, 1);
		setMM(cpu, 0);
		D = R[df] + 2;
		R[df] = D;
		if(dati(cpu)) return 1;
		goto DST12;
	case 4:
		// DST02
		D = setBA(cpu, R[df]-ai, df, pse, !b);
		setMM(cpu, 1);
		goto DST03;
		break;
	case 5:
		// DST05
		D = setBA(cpu, R[df]-2, df, 0, 1);
		setMM(cpu, 0);
		R[df] = D;
		if(dati(cpu)) return 1;
		goto DST12;
	case 6:
		// DST06/07
		 setBA(cpu, R[PC], PC, 0, 1);	// only if not still set from fetch
		setMM(cpu, 0);
		D = R[PC] + 2;
		R[PC] = D;
		if(dati(cpu)) return 1;
		// DST09
		B = R[DEST] = UNIBUS_DATA;
		// DST10
		setBA(cpu, R[df]+B, df, pse, !b);
		setMM(cpu, 1);
		goto DST14;
	case 7:
		// DST06/07
		 setBA(cpu, R[PC], PC, 0, 1);	// only if not still set from fetch
		setMM(cpu, 0);
		D = R[PC] + 2;
		R[PC] = D;
		if(dati(cpu)) return 1;
		// DST09
		B = R[DEST] = UNIBUS_DATA;
		// DST11
		setBA(cpu, R[df]+B, df, 0, 1);
		setMM(cpu, 0);
		if(dati(cpu)) return 1;
		// DST12
		B = R[DEST] = UNIBUS_DATA;
		// DST13
		setBA(cpu, R[DEST], DEST, pse, !b);
		setMM(cpu, 1);
		goto DST14;
//

		DST03:
		R[df] = D;
		if(datix(cpu, pse)) return 1;
		goto DST15;

		DST12:
		B = R[DEST] = UNIBUS_DATA;
		// DST13:
		setBA(cpu, R[DEST], DEST, pse, !b);
		setMM(cpu, 1);
		DST14:
		if(datix(cpu, pse)) return 1;
		DST15:
		B = R[DEST] = UNIBUS_DATA;
	}
	if(b && BA&1){
		// DST16
		D = B&0177400 | (B>>8)&0377;
		// DST17
		B = R[DEST] = D;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %r14d
movl %edx, %ebp
movq %rdi, %rbx
movl %esi, %r15d
andl $0x7, %r15d
movl %esi, %eax
shrl $0x3, %eax
cmpl $0x6, %r15d
jne 0x650c
movb 0x86(%rbx), %cl
andb $0x2, %cl
shrb %cl
movzbl %cl, %ecx
leal 0x6(,%rcx,8), %r15d
movl %r15d, %ecx
notl %ecx
xorl %r12d, %r12d
btl $0x3, %esi
adcw $0x1, %r12w
testb $0x6, %cl
movl $0x2, %ecx
cmovel %ecx, %r12d
testl %ebp, %ebp
cmovel %ecx, %r12d
movl %eax, %eax
leaq 0x2c64(%rip), %rcx      # 0x919c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movl %r15d, %eax
movzwl (%rbx,%rax,2), %esi
jmp 0x6821
movl %r15d, %eax
movzwl (%rbx,%rax,2), %ecx
addl $-0x2, %ecx
movl 0x38(%rbx), %edx
movl %edx, %esi
andl $-0x61, %esi
orl $0x40, %esi
movl %esi, 0x38(%rbx)
movw %cx, 0x24(%rbx)
movw %cx, 0x22(%rbx)
testb $0x8, %dl
jne 0x6702
movzwl 0x86(%rbx), %edx
movw %dx, 0x84(%rbx)
movzwl 0x138(%rbx), %edx
andl $0x1, %edx
jmp 0x670d
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movl %r15d, %eax
movzwl (%rbx,%rax,2), %eax
subl %r12d, %eax
movzwl %ax, %r12d
movq %rbx, %rdi
movl %r12d, %esi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x59fa
movw %r12w, 0x22(%rbx)
testb $0x8, 0x38(%rbx)
jne 0x6715
movzwl 0x86(%rbx), %eax
movw %ax, 0x84(%rbx)
movzwl 0x138(%rbx), %eax
xorl %ecx, %ecx
testl $0x101, %eax            # imm = 0x101
setne %cl
movl %ecx, 0x13c(%rbx)
jmp 0x67be
movl %r15d, %eax
movzwl (%rbx,%rax,2), %ecx
movl 0x38(%rbx), %edx
movl %edx, %esi
andl $-0x61, %esi
orl $0x40, %esi
movl %esi, 0x38(%rbx)
movw %cx, 0x24(%rbx)
testb $0x8, %dl
jne 0x672d
movzwl 0x86(%rbx), %ecx
movw %cx, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
jmp 0x6738
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movl %r15d, %r13d
movzwl (%rbx,%r13,2), %esi
movq %rbx, %rdi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x59fa
testb $0x8, 0x38(%rbx)
jne 0x67a3
movzwl 0x86(%rbx), %eax
movw %ax, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
xorl %eax, %eax
testl $0x101, %ecx            # imm = 0x101
setne %al
jmp 0x67ae
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %ecx
movl %ecx, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
testb $0x8, %cl
jne 0x67ce
movzwl 0x86(%rbx), %ecx
movw %cx, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
jmp 0x67d9
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %ecx
movl %ecx, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
testb $0x8, %cl
jne 0x68c1
movzwl 0x86(%rbx), %ecx
movw %cx, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
jmp 0x68cc
movw $0x0, 0x84(%rbx)
xorl %edx, %edx
movl %edx, 0x13c(%rbx)
jmp 0x6749
movw $0x0, 0x84(%rbx)
movl $0x0, 0x13c(%rbx)
jmp 0x67be
movw $0x0, 0x84(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x13c(%rbx)
movzwl (%rbx,%rax,2), %ecx
addl $0x2, %ecx
movw %cx, 0x22(%rbx)
movw %cx, (%rbx,%rax,2)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x70ca
movl $0x1, %r12d
testl %eax, %eax
jne 0x6874
movl 0x38(%rbx), %eax
andl $-0x61, %eax
leal 0x40(%rax), %ecx
testl %ebp, %ebp
movq 0x28(%rbx), %rdx
movzwl 0xc(%rdx), %edx
movw %dx, 0x14(%rbx)
cmovnel %eax, %ecx
movw %dx, 0x20(%rbx)
movl %ecx, 0x38(%rbx)
movw %dx, 0x24(%rbx)
testb $0x8, %cl
je 0x6839
movw $0x0, 0x84(%rbx)
xorl %eax, %eax
jmp 0x6856
movw $0x0, 0x84(%rbx)
xorl %eax, %eax
movl %eax, 0x13c(%rbx)
addw (%rbx,%r13,2), %r12w
movw %r12w, 0x22(%rbx)
movzwl 0x22(%rbx), %eax
movl %r15d, %ecx
movw %ax, (%rbx,%rcx,2)
jmp 0x685f
movw $0x0, 0x84(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x13c(%rbx)
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x70ca
movl $0x1, %r12d
testl %eax, %eax
jne 0x6874
xorl %r8d, %r8d
testl %ebp, %ebp
sete %r8b
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
movl %r15d, %ecx
addw (%rbx,%rcx,2), %ax
movzwl %ax, %esi
movq %rbx, %rdi
movl %r15d, %edx
movl %r14d, %ecx
callq 0x59fa
testb $0x8, 0x38(%rbx)
jne 0x6793
movzwl 0x86(%rbx), %eax
movw %ax, 0x84(%rbx)
movzwl 0x138(%rbx), %eax
testl $0x101, %eax            # imm = 0x101
setne %al
movzbl %al, %eax
movl %eax, 0x13c(%rbx)
movq %rbx, %rdi
movl %r14d, %esi
callq 0x70ca
movl $0x1, %r12d
testl %eax, %eax
je 0x6886
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
testl %ebp, %ebp
je 0x6874
testb $0x1, 0x24(%rbx)
je 0x6874
movl %eax, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
movzwl %ax, %eax
shrl $0x8, %eax
orl %ecx, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
jmp 0x6874
movw $0x0, 0x84(%rbx)
xorl %ecx, %ecx
movl %ecx, 0x13c(%rbx)
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x70ca
movl $0x1, %r12d
testl %eax, %eax
jne 0x6874
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x14(%rbx)
movw %ax, 0x20(%rbx)
movl %r15d, %ecx
addw (%rbx,%rcx,2), %ax
movl 0x38(%rbx), %ecx
movl %ecx, %edx
andl $-0x61, %edx
orl $0x40, %edx
movl %edx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
testb $0x8, %cl
jne 0x6939
movzwl 0x86(%rbx), %eax
movw %ax, 0x84(%rbx)
movzwl 0x138(%rbx), %eax
andl $0x1, %eax
jmp 0x6944
movw $0x0, 0x84(%rbx)
xorl %eax, %eax
movl %eax, 0x13c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x70ca
jmp 0x675d
leaq 0x2b90(%rip), %rdi      # 0x94f0
leaq 0x2b8b(%rip), %rsi      # 0x94f2
leaq 0x2df5(%rip), %rcx      # 0x9763
movl $0x303, %edx            # imm = 0x303
callq 0x20d0