// File: /workspace/github_c_makefile_star2_O2/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 %r15
pushq %r14
pushq %rbx
movq %rsi, %r14
movl %edi, %ebx
leaq 0x1148f(%rip), %rdi     # 0x13c20
movl $0x90, %edx
xorl %esi, %esi
callq 0x20e0
andq $0x0, 0x1151b(%rip)     # 0x13cc0
xorps %xmm0, %xmm0
movups %xmm0, 0x11501(%rip)    # 0x13cb0
leaq 0x114fa(%rip), %r15     # 0x13cb0
movq %r15, 0x1148b(%rip)     # 0x13c48
leaq 0x79dc(%rip), %rsi      # 0xa1a0
movq %r15, %rdi
callq 0x234c
leaq 0x7acd(%rip), %rsi      # 0xa2a0
movq %r15, %rdi
callq 0x234c
leaq 0x7a7e(%rip), %rsi      # 0xa260
movq %r15, %rdi
callq 0x234c
leaq 0x7a2f(%rip), %rsi      # 0xa220
movq %r15, %rdi
callq 0x234c
leaq 0x7ae0(%rip), %rsi      # 0xa2e0
movq %r15, %rdi
callq 0x234c
leaq 0x7b11(%rip), %rsi      # 0xa320
movq %r15, %rdi
callq 0x234c
leaq 0x7b42(%rip), %rsi      # 0xa360
movq %r15, %rdi
callq 0x234c
leaq 0x79b3(%rip), %rsi      # 0xa1e0
movq %r15, %rdi
callq 0x234c
cmpq $0x0, 0x113db(%rip)     # 0x13c18
jne 0x2849
movq (%r14), %rax
movq %rax, 0x113cf(%rip)     # 0x13c18
addq $0x8, %r14
addl $-0x2, %ebx
movq (%r14), %rax
testq %rax, %rax
je 0x287a
cmpb $0x2d, (%rax)
jne 0x287a
movzbl 0x1(%rax), %ecx
cmpl $0x2d, %ecx
je 0x286c
testl %ecx, %ecx
jne 0x2872
jmp 0x287a
cmpb $0x0, 0x2(%rax)
je 0x287c
addq $0x8, %r14
decl %ebx
jmp 0x2850
incl %ebx
testl %ebx, %ebx
js 0x290c
leaq 0x47a2(%rip), %rdi      # 0x702d
callq 0x2407
leaq 0x11389(%rip), %rbx     # 0x13c20
movq %rbx, %rdi
callq 0x2ab7
leaq 0xfb3e(%rip), %rdi      # 0x123e4
callq 0x6315
leaq 0xfb6e(%rip), %r14      # 0x12420
leaq 0x477c(%rip), %rdx      # 0x7035
movq %r14, %rdi
xorl %esi, %esi
callq 0x5844
leaq 0x4779(%rip), %rdx      # 0x7043
pushq $0x1
popq %rsi
movq %r14, %rdi
callq 0x5844
leaq 0x10bec(%rip), %rdi     # 0x134c8
leaq 0x476e(%rip), %rdx      # 0x7051
xorl %esi, %esi
callq 0x60b6
movw $0xf7c0, %ax            # imm = 0xF7C0
movw %ax, 0x11339(%rip)      # 0x13c2e
movw %ax, 0x113ac(%rip)      # 0x13ca8
movq %rbx, %rdi
callq 0x4a45
xorl %eax, %eax
popq %rbx
popq %r14
popq %r15
retq
callq 0x2759
nopl (%rax)