// File: /workspace/github_c_makefile_star2_O1/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 0x11314(%rip), %rdi     # 0x13c20
movl $0x90, %edx
xorl %esi, %esi
callq 0x20e0
xorps %xmm0, %xmm0
movups %xmm0, 0x1138e(%rip)    # 0x13cb0
movq $0x0, 0x11393(%rip) # 0x13cc0
leaq 0x1137c(%rip), %rax     # 0x13cb0
movq %rax, 0x1130d(%rip)     # 0x13c48
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x293b
leaq 0x7853(%rip), %rax      # 0xa1a0
movq %rax, (%rcx)
movq $0x0, 0x7845(%rip) # 0xa1a0
leaq 0x1134e(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x2962
leaq 0x792c(%rip), %rcx      # 0xa2a0
movq %rcx, (%rax)
movq $0x0, 0x791e(%rip) # 0xa2a0
leaq 0x11327(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x2989
leaq 0x78c5(%rip), %rcx      # 0xa260
movq %rcx, (%rax)
movq $0x0, 0x78b7(%rip) # 0xa260
leaq 0x11300(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x29b0
leaq 0x785e(%rip), %rcx      # 0xa220
movq %rcx, (%rax)
movq $0x0, 0x7850(%rip) # 0xa220
leaq 0x112d9(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x29d7
leaq 0x78f7(%rip), %rcx      # 0xa2e0
movq %rcx, (%rax)
movq $0x0, 0x78e9(%rip) # 0xa2e0
leaq 0x112b2(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x29fe
leaq 0x7910(%rip), %rcx      # 0xa320
movq %rcx, (%rax)
movq $0x0, 0x7902(%rip) # 0xa320
leaq 0x1128b(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x2a25
leaq 0x7929(%rip), %rcx      # 0xa360
movq %rcx, (%rax)
movq $0x0, 0x791b(%rip) # 0xa360
leaq 0x11264(%rip), %rcx     # 0x13cb0
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x2a4c
leaq 0x7782(%rip), %rcx      # 0xa1e0
movq %rcx, (%rax)
movq $0x0, 0x7774(%rip) # 0xa1e0
cmpq $0x0, 0x111a4(%rip)     # 0x13c18
jne 0x2a80
movq (%rbx), %rax
movq %rax, 0x11198(%rip)     # 0x13c18
leal -0x1(%r14), %eax
movq 0x8(%rbx), %rsi
testq %rsi, %rsi
je 0x2ad5
cmpb $0x2d, (%rsi)
jne 0x2ad5
leaq 0x8(%rbx), %rcx
leaq 0x1(%rsi), %rdx
movzbl 0x1(%rsi), %edi
cmpl $0x2d, %edi
je 0x2aa9
testl %edi, %edi
jne 0x2aaf
jmp 0x2ad5
cmpb $0x0, 0x2(%rsi)
je 0x2ac6
cmpb $0x0, (%rdx)
leaq 0x1(%rdx), %rdx
jne 0x2aaf
movb $0x1, %dl
movq %rcx, %rbx
movl %eax, %r14d
testb %dl, %dl
jne 0x2a80
jmp 0x2ad5
addl $-0x2, %r14d
addq $0x10, %rbx
xorl %edx, %edx
movl %r14d, %eax
jmp 0x2abd
testl %eax, %eax
js 0x2b69
leaq 0x4549(%rip), %rdi      # 0x702d
callq 0x2549
leaq 0x11130(%rip), %rbx     # 0x13c20
movq %rbx, %rdi
callq 0x2d13
leaq 0xf8e5(%rip), %rdi      # 0x123e4
callq 0x673f
leaq 0xf915(%rip), %r14      # 0x12420
leaq 0x4523(%rip), %rdx      # 0x7035
movq %r14, %rdi
xorl %esi, %esi
callq 0x5ba5
leaq 0x4520(%rip), %rdx      # 0x7043
movq %r14, %rdi
movl $0x1, %esi
callq 0x5ba5
leaq 0x10991(%rip), %rdi     # 0x134c8
leaq 0x4513(%rip), %rdx      # 0x7051
xorl %esi, %esi
callq 0x643f
movw $0xf7c0, %ax            # imm = 0xF7C0
movw %ax, 0x110de(%rip)      # 0x13c2e
movw %ax, 0x11151(%rip)      # 0x13ca8
movq %rbx, %rdi
callq 0x4d00
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x2260
nop