// File: /workspace/github_c_makefile_star2_O2/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 0x5a8f
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
pushq $0x2
popq %rcx
cmovel %ecx, %r12d
testl %ebp, %ebp
cmovel %ecx, %r12d
movl %eax, %eax
leaq 0x26d3(%rip), %rcx      # 0x818c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
pushq $0x1
popq %r14
jmpq *%rax
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl %r15d, %ecx
movzwl (%rbx,%rcx,2), %ecx
jmp 0x5caf
movl %r15d, %r15d
movzwl (%rbx,%r15,2), %eax
addl $-0x2, %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movw %ax, 0x22(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl 0x22(%rbx), %eax
movw %ax, (%rbx,%r15,2)
jmp 0x5c8c
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl %r15d, %r15d
movzwl (%rbx,%r15,2), %ecx
subl %r12d, %ecx
movl 0x38(%rbx), %edx
andl $-0x61, %edx
shll $0x6, %eax
orl %edx, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
movw %cx, 0x22(%rbx)
pushq $0xc
popq %rsi
movq %rbx, %rdi
callq 0x59d2
movzwl 0x22(%rbx), %r12d
jmp 0x5bb8
movl %r15d, %r15d
movzwl (%rbx,%r15,2), %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl (%rbx,%r15,2), %eax
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, (%rbx,%r15,2)
jmp 0x5c8c
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movl %r15d, %r15d
movzwl (%rbx,%r15,2), %ecx
movl 0x38(%rbx), %edx
andl $-0x61, %edx
shll $0x6, %eax
orl %edx, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
pushq $0xc
popq %rsi
movq %rbx, %rdi
callq 0x59d2
addw (%rbx,%r15,2), %r12w
movw %r12w, 0x22(%rbx)
movw %r12w, (%rbx,%r15,2)
jmp 0x5ccc
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl 0xe(%rbx), %eax
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
jne 0x5cd8
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movq 0x28(%rbx), %rcx
movzwl 0xc(%rcx), %ecx
movw %cx, 0x12(%rbx)
movw %cx, 0x20(%rbx)
movl %r15d, %edx
addw (%rbx,%rdx,2), %cx
jmp 0x5caf
movzwl 0xe(%rbx), %eax
movl 0x38(%rbx), %ecx
andl $-0x61, %ecx
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movzwl 0xe(%rbx), %eax
addl $0x2, %eax
movw %ax, 0x22(%rbx)
movw %ax, 0xe(%rbx)
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
jne 0x5cd8
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
orl $0x40, %ecx
movl %ecx, 0x38(%rbx)
movw %ax, 0x24(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x59d2
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
jne 0x5cd8
xorl %eax, %eax
testl %ebp, %ebp
sete %al
movq 0x28(%rbx), %rcx
movzwl 0xc(%rcx), %ecx
movw %cx, 0x12(%rbx)
movw %cx, 0x20(%rbx)
movl 0x38(%rbx), %edx
andl $-0x61, %edx
shll $0x6, %eax
orl %edx, %eax
movl %eax, 0x38(%rbx)
movw %cx, 0x24(%rbx)
pushq $0xc
popq %rsi
movq %rbx, %rdi
callq 0x59d2
movq %rbx, %rdi
callq 0x5a53
testl %eax, %eax
je 0x5ce4
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 0x5cd8
testb $0x1, 0x24(%rbx)
je 0x5cd8
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 0x5cd8
leaq 0x27fe(%rip), %rdi      # 0x8524
leaq 0x27f9(%rip), %rsi      # 0x8526
leaq 0x2a01(%rip), %rcx      # 0x8735
movl $0x2a1, %edx            # imm = 0x2A1
callq 0x20d0