// File: /workspace/github_c_makefile_star2_O1/aap[P]pdp11/kd11a.c
// Function: fetch_src
static int
fetch_src(KD11A *cpu, int m, int b)
{
	int sm, sf;
	int ai;

	sf = m&7;
	sm = m>>3;
	if(sf == SP && USER) sf = USP;	// KT11-SP
	ai = 1 + (!b || (sf&6)==6 || sm&1);
	switch(sm){
	case 0:
		assert(0);	// we don't do that here
		break;
	case 1:
		// SRC00
		setBA(cpu, R[sf], sf, 0, !b);
		setMM(cpu, 014);
		goto SRC14;
	case 2:
		// SRC01
		setBA(cpu, R[sf], sf, 0, !b);
		setMM(cpu, 014);
		D = R[sf] + ai;
		goto SRC03;
	case 3:
		// SRC04
		setBA(cpu, R[sf], sf, 0, 1);
		setMM(cpu, 0);
		D = R[sf] + 2;
		R[sf] = D;
		if(dati(cpu)) return 1;
		goto SRC12;
	case 4:
		// SRC02
		D = setBA(cpu, R[sf]-ai, sf, 0, !b);
		setMM(cpu, 014);
		goto SRC03;
	case 5:
		// SRC05
		D = setBA(cpu, R[sf]-2, sf, 0, 1);
		setMM(cpu, 0);
		R[sf] = D;
		if(dati(cpu)) return 1;
		goto SRC12;
	case 6:
		// SRC06
		 setBA(cpu, R[PC], PC, 0, 1);	// actually still set from fetch
		setMM(cpu, 0);
		D = R[PC] + 2;
		R[PC] = D;
		if(dati(cpu)) return 1;
		// SRC07
		B = R[SOURCE] = UNIBUS_DATA;
		// SRC08
		setBA(cpu, R[sf]+B, sf, 0, !b);
		setMM(cpu, 014);
		goto SRC14;
	case 7:
		// SRC09
		 setBA(cpu, R[PC], PC, 0, 1);	// actually still set from fetch
		setMM(cpu, 0);
		D = R[PC] + 2;
		R[PC] = D;
		if(dati(cpu)) return 1;
		// SRC10
		B = R[SOURCE] = UNIBUS_DATA;
		// SRC11
		setBA(cpu, R[sf]+B, sf, 0, 1);
		setMM(cpu, 0);
		if(dati(cpu)) return 1;
		goto SRC12;
//

		SRC03:
		R[sf] = D;
		if(dati(cpu)) return 1;
		goto SRC15;

		SRC12:
		B = R[SOURCE] = UNIBUS_DATA;
		// SRC13
		setBA(cpu, R[SOURCE], SOURCE, 0, !b);
		setMM(cpu, 014);
		SRC14:
		if(dati(cpu)) return 1;
		SRC15:
		B = R[SOURCE] = UNIBUS_DATA;
	}
	if(b && BA&1){
		// SRC16
		D = B&0177400 | (B>>8)&0377;
		// SRC17
		B = R[SOURCE] = D;
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %edx, %ebp
movq %rdi, %rbx
movl %esi, %r15d
andl $0x7, %r15d
movl %esi, %eax
shrl $0x3, %eax
cmpl $0x6, %r15d
jne 0x5af3
movb 0x86(%rbx), %cl
andb $0x2, %cl
shrb %cl
movzbl %cl, %ecx
leal 0x6(,%rcx,8), %r15d
movl %r15d, %ecx
notl %ecx
xorl %r14d, %r14d
btl $0x3, %esi
adcw $0x1, %r14w
testb $0x6, %cl
movl $0x2, %ecx
cmovel %ecx, %r14d
testl %ebp, %ebp
cmovel %ecx, %r14d
movl %eax, %eax
leaq 0x363d(%rip), %rcx      # 0x915c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x38(%rbx), %eax
andl $-0x61, %eax
leal 0x40(%rax), %ecx
testl %ebp, %ebp
movl %r15d, %edx
movzwl (%rbx,%rdx,2), %edx
jmp 0x5d14
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 0x5cb2
movzwl 0x86(%rbx), %edx
movw %dx, 0x84(%rbx)
movzwl 0x138(%rbx), %edx
andl $0x1, %edx
jmp 0x5cbd
movl %r15d, %eax
movzwl (%rbx,%rax,2), %eax
subl %r14d, %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
leal 0x40(%rcx), %edx
testl %ebp, %ebp
cmovnel %ecx, %edx
movl %edx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movw %ax, 0x22(%rbx)
movq %rbx, %rdi
movl $0xc, %esi
callq 0x5a3a
jmp 0x5c2a
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 0x5cc5
movzwl 0x86(%rbx), %ecx
movw %cx, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
jmp 0x5cd0
movl 0x38(%rbx), %eax
andl $-0x61, %eax
leal 0x40(%rax), %ecx
testl %ebp, %ebp
movl %r15d, %r12d
movzwl (%rbx,%r12,2), %edx
cmovnel %eax, %ecx
movl %ecx, 0x38(%rbx)
movw %dx, 0x24(%rbx)
movq %rbx, %rdi
movl $0xc, %esi
callq 0x5a3a
addw (%rbx,%r12,2), %r14w
movw %r14w, 0x22(%rbx)
movzwl 0x22(%rbx), %eax
movl %r15d, %ecx
movw %ax, (%rbx,%rcx,2)
jmp 0x5d2b
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 0x5d86
movzwl 0x86(%rbx), %ecx
movw %cx, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
jmp 0x5d91
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 0x5de7
movzwl 0x86(%rbx), %ecx
movw %cx, 0x84(%rbx)
movzwl 0x138(%rbx), %ecx
andl $0x1, %ecx
jmp 0x5df2
movw $0x0, 0x84(%rbx)
xorl %edx, %edx
movl %edx, 0x13c(%rbx)
jmp 0x5ce1
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, %r14d
testl %eax, %eax
jne 0x5d3f
movl 0x38(%rbx), %eax
andl $-0x61, %eax
leal 0x40(%rax), %ecx
testl %ebp, %ebp
movq 0x28(%rbx), %rdx
movzwl 0xc(%rdx), %edx
movw %dx, 0x12(%rbx)
movw %dx, 0x20(%rbx)
cmovnel %eax, %ecx
movl %ecx, 0x38(%rbx)
movw %dx, 0x24(%rbx)
movq %rbx, %rdi
movl $0xc, %esi
callq 0x5a3a
movq %rbx, %rdi
xorl %esi, %esi
callq 0x70ca
movl $0x1, %r14d
testl %eax, %eax
je 0x5d4b
movl %r14d, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x12(%rbx)
movw %ax, 0x20(%rbx)
testl %ebp, %ebp
je 0x5d3f
testb $0x1, 0x24(%rbx)
je 0x5d3f
movl %eax, %ecx
andl $0xffffff00, %ecx       # imm = 0xFFFFFF00
movzwl %ax, %eax
shrl $0x8, %eax
orl %ecx, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0x12(%rbx)
movw %ax, 0x20(%rbx)
jmp 0x5d3f
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, %r14d
testl %eax, %eax
jne 0x5d3f
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x12(%rbx)
movw %ax, 0x20(%rbx)
movl %r15d, %ecx
addw (%rbx,%rcx,2), %ax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
leal 0x40(%rcx), %edx
testl %ebp, %ebp
cmovnel %ecx, %edx
movl %edx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
jmp 0x5d1e
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, %r14d
testl %eax, %eax
jne 0x5d3f
movq 0x28(%rbx), %rax
movzwl 0xc(%rax), %eax
movw %ax, 0x12(%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 0x5e63
movzwl 0x86(%rbx), %eax
movw %ax, 0x84(%rbx)
movzwl 0x138(%rbx), %eax
andl $0x1, %eax
jmp 0x5e6e
movw $0x0, 0x84(%rbx)
xorl %eax, %eax
movl %eax, 0x13c(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x70ca
jmp 0x5cf5
leaq 0x3666(%rip), %rdi      # 0x94f0
leaq 0x3661(%rip), %rsi      # 0x94f2
leaq 0x3869(%rip), %rcx      # 0x9701
movl $0x2a1, %edx            # imm = 0x2A1
callq 0x20d0