// File: /workspace/github_c_makefile_star2_O3/aap[P]pdp11/1120.c
// Function: main
int
xmain(int argc, char *argv[])
{
	memset(&cpu, 0, sizeof(KA11));
	memset(&bus, 0, sizeof(Bus));
	cpu.bus = &bus;
	busadddev(&bus, &membusdev);
	busadddev(&bus, &kwbusdev);
	busadddev(&bus, &klbusdev);
	busadddev(&bus, &kebusdev);
	busadddev(&bus, &rfbusdev);
	busadddev(&bus, &rkbusdev);
	busadddev(&bus, &dcbusdev);
	busadddev(&bus, &rombusdev);

	ARGBEGIN{
	}ARGEND;

	if(argc < 0)
		usage();

	loadmem("mem.txt");

	reset(&cpu);

	ttyopen(&kl11.tty);

#ifdef AUTODIAG
	if(rundiag(&cpu, "maindec/ZKAAA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKABA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKACA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKADA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAEA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAFA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAGA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAHA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAIA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAJA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAKA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKALA0.BIN")) return 0;
	if(rundiag(&cpu, "maindec/ZKAMA0.BIN")) return 0;
//	if(rundiag(&cpu, "maindec/maindec-11-d0nc.pb.bin")) return 0;
	printf("passed all diagnostics\n");
		return 0;
#endif

	// to boot UNIX v1
	attach_rs11(&rf11, 0, "unix1/rf0.dsk");
	attach_rs11(&rf11, 1, "unix1/rf1.dsk");
	attach_rk05(&rk11, 0, "unix1/rk0.dsk");

//	cpu.r[7] = 0200;
//	cpu.sw = 0104000;
	cpu.r[7] = 0173700;
	cpu.sw = 0173700;
	run(&cpu);

	return 0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
movq %rsi, %rbx
movl %edi, %r14d
leaq 0x11415(%rip), %rdi     # 0x13c20
movl $0x90, %edx
xorl %esi, %esi
callq 0x20e0
xorps %xmm0, %xmm0
movups %xmm0, 0x11497(%rip)    # 0x13cb8
leaq 0x11488(%rip), %rax     # 0x13cb0
movq %rax, 0x11419(%rip)     # 0x13c48
leaq 0x796a(%rip), %rcx      # 0xa1a0
movq %rcx, 0x11473(%rip)     # 0x13cb0
movq $0x0, 0x7958(%rip) # 0xa1a0
movq %rcx, %rdx
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x2848
leaq 0x7a46(%rip), %rcx      # 0xa2a0
movq %rcx, (%rdx)
movq $0x0, 0x7a38(%rip) # 0xa2a0
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x2868
leaq 0x79e6(%rip), %rax      # 0xa260
movq %rax, (%rcx)
movq $0x0, 0x79d8(%rip) # 0xa260
leaq 0x11421(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x288f
leaq 0x797f(%rip), %rcx      # 0xa220
movq %rcx, (%rax)
movq $0x0, 0x7971(%rip) # 0xa220
leaq 0x113fa(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x28b6
leaq 0x7a18(%rip), %rcx      # 0xa2e0
movq %rcx, (%rax)
movq $0x0, 0x7a0a(%rip) # 0xa2e0
leaq 0x113d3(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x28dd
leaq 0x7a31(%rip), %rcx      # 0xa320
movq %rcx, (%rax)
movq $0x0, 0x7a23(%rip) # 0xa320
leaq 0x113ac(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x2904
leaq 0x7a4a(%rip), %rcx      # 0xa360
movq %rcx, (%rax)
movq $0x0, 0x7a3c(%rip) # 0xa360
leaq 0x11385(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x292b
leaq 0x78a3(%rip), %rcx      # 0xa1e0
movq %rcx, (%rax)
movq $0x0, 0x7895(%rip) # 0xa1e0
movq 0x112c6(%rip), %rdi     # 0x13c18
testq %rdi, %rdi
jne 0x2961
movq (%rbx), %rdi
movq %rdi, 0x112b7(%rip)     # 0x13c18
leal -0x1(%r14), %ecx
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
je 0x29bb
addq $0x8, %rbx
movl %ecx, %eax
cmpb $0x2d, (%rdx)
jne 0x29b0
leaq 0x1(%rdx), %rcx
movzbl 0x1(%rdx), %esi
cmpl $0x2d, %esi
je 0x298c
testl %esi, %esi
jne 0x2992
jmp 0x29b0
cmpb $0x0, 0x2(%rdx)
je 0x29b4
cmpb $0x0, (%rcx)
leaq 0x1(%rcx), %rcx
jne 0x2992
leal -0x1(%rax), %ecx
movq 0x8(%rbx), %rdx
addq $0x8, %rbx
movl %eax, %r14d
testq %rdx, %rdx
jne 0x2972
jmp 0x29bb
movl %eax, %ecx
jmp 0x29bb
addl $-0x2, %r14d
movl %r14d, %ecx
testl %ecx, %ecx
js 0x2a4f
leaq 0x4663(%rip), %rdi      # 0x702d
callq 0x2449
leaq 0x1124a(%rip), %rbx     # 0x13c20
movq %rbx, %rdi
callq 0x2bf7
leaq 0xf9ff(%rip), %rdi      # 0x123e4
callq 0x67a3
leaq 0xfa2f(%rip), %r14      # 0x12420
leaq 0x463d(%rip), %rdx      # 0x7035
movq %r14, %rdi
xorl %esi, %esi
callq 0x5ba9
leaq 0x463a(%rip), %rdx      # 0x7043
movq %r14, %rdi
movl $0x1, %esi
callq 0x5ba9
leaq 0x10aab(%rip), %rdi     # 0x134c8
leaq 0x462d(%rip), %rdx      # 0x7051
xorl %esi, %esi
callq 0x64a4
movw $0xf7c0, %ax            # imm = 0xF7C0
movw %ax, 0x111f8(%rip)      # 0x13c2e
movw %ax, 0x1126b(%rip)      # 0x13ca8
movq %rbx, %rdi
callq 0x4cff
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x2260