// File: /workspace/github_c_makefile_star2_O0/aap[P]pdp11/kd11a.c
// Function: remapBA
static int
remapBA(KD11A *cpu, int wr)
{
#ifdef KT11
	int i, pg, abrt;
	cpu->wrpg = nil;
	if(!cpu->relocate){
		PBA = ubxt(BA);
		cpu->flags &= ~FLAG_FAULT;
		return 0;
	}
	pg = BA>>13;
	i = (cpu->mode&2 ? 0 : 8) | pg;
	PBA = ((BA&017777) + (cpu->par[i]<<6)) & 0777777;

	abrt = 0;
	// not resident (or illegal mode)
	if((cpu->acf[i]&2)==0 || (6>>cpu->mode)&1)
		abrt |= 0100000;
	// page length
	if(cpu->acf[i]&010 ? ((BA&017700) < cpu->plf[i]) : ((BA&017700) > cpu->plf[i]))
		abrt |= 0040000;
	// read-only
	if(wr && (cpu->acf[i]&6)==2)
		abrt |= 0020000;
	abrt |= cpu->mode<<5 | pg<<1;
	if(!ABORT)
		SETMASK(cpu->sr0, abrt, 0160156);
	if((abrt&0160000) && !(cpu->flags & FLAG_STALL) && !(cpu->flags&FLAG_CKODA && BA&1)){
		cpu->flags |= FLAG_FAULT;
		return 1;
	}
	if(wr &&
	   !((PBA&0777770) == 0777570 && (PBA&0777776) != 0777570))	// ignore write to SR registers
		cpu->wrpg = &cpu->acf[i];
	cpu->flags &= ~FLAG_FAULT;
	return 0;
#else
	PBA = ubxt(BA);
	return 0;
#endif
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x130(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x13c(%rax)
jne 0x9481
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %edi
callq 0x9b40
movl %eax, %ecx
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0xfffffdff, %ecx       # imm = 0xFFFFFDFF
movl %ecx, 0x38(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x96c8
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %eax
sarl $0xd, %eax
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x84(%rax), %edx
andl $0x2, %edx
movl $0x8, %eax
xorl %ecx, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
orl -0x1c(%rbp), %eax
movl %eax, -0x18(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %ecx
andl $0x1fff, %ecx           # imm = 0x1FFF
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rdx
movzwl 0x8c(%rax,%rdx,2), %eax
shll $0x6, %eax
addl %eax, %ecx
andl $0x3ffff, %ecx          # imm = 0x3FFFF
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl %ecx, 0x8(%rax)
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0xac(%rax,%rcx,4), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0x951c
movq -0x10(%rbp), %rax
movzwl 0x84(%rax), %ecx
movl $0x6, %eax
sarl %cl, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x9527
movl -0x20(%rbp), %eax
orl $0x8000, %eax           # imm = 0x8000
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0xac(%rax,%rcx,4), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0x955e
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %eax
andl $0x1fc0, %eax           # imm = 0x1FC0
movq -0x10(%rbp), %rcx
movslq -0x18(%rbp), %rdx
cmpl 0xec(%rcx,%rdx,4), %eax
jl 0x957c
jmp 0x9587
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %eax
andl $0x1fc0, %eax           # imm = 0x1FC0
movq -0x10(%rbp), %rcx
movslq -0x18(%rbp), %rdx
cmpl 0xec(%rcx,%rdx,4), %eax
jle 0x9587
movl -0x20(%rbp), %eax
orl $0x4000, %eax           # imm = 0x4000
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
je 0x95af
movq -0x10(%rbp), %rax
movslq -0x18(%rbp), %rcx
movl 0xac(%rax,%rcx,4), %eax
andl $0x6, %eax
cmpl $0x2, %eax
jne 0x95af
movl -0x20(%rbp), %eax
orl $0x2000, %eax           # imm = 0x2000
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x84(%rax), %eax
shll $0x5, %eax
movl -0x1c(%rbp), %ecx
shll %ecx
orl %ecx, %eax
orl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movzwl 0x138(%rax), %eax
andl $0xe000, %eax           # imm = 0xE000
cmpl $0x0, %eax
jne 0x9608
movq -0x10(%rbp), %rax
movzwl 0x138(%rax), %eax
andl $0xffff1f91, %eax       # imm = 0xFFFF1F91
movl -0x20(%rbp), %ecx
andl $0xe06e, %ecx           # imm = 0xE06E
orl %ecx, %eax
movw %ax, %cx
movq -0x10(%rbp), %rax
movw %cx, 0x138(%rax)
movl -0x20(%rbp), %eax
andl $0xe000, %eax           # imm = 0xE000
cmpl $0x0, %eax
je 0x965c
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
jne 0x965c
movq -0x10(%rbp), %rax
movl 0x38(%rax), %eax
andl $0x40, %eax
cmpl $0x0, %eax
je 0x9643
movq -0x10(%rbp), %rax
movzwl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x965c
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
orl $0x200, %ecx            # imm = 0x200
movl %ecx, 0x38(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x96c8
cmpl $0x0, -0x14(%rbp)
je 0x96b1
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %eax
andl $0x3fff8, %eax          # imm = 0x3FFF8
cmpl $0x3ff78, %eax          # imm = 0x3FF78
jne 0x9690
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl 0x8(%rax), %eax
andl $0x3fffe, %eax          # imm = 0x3FFFE
cmpl $0x3ff78, %eax          # imm = 0x3FF78
jne 0x96b1
movq -0x10(%rbp), %rcx
addq $0xac, %rcx
movslq -0x18(%rbp), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x130(%rax)
movq -0x10(%rbp), %rax
movl 0x38(%rax), %ecx
andl $0xfffffdff, %ecx       # imm = 0xFFFFFDFF
movl %ecx, 0x38(%rax)
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)