// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x15193(%rip), %rdi     # 0x17c30
xorl %esi, %esi
movl $0x90, %edx
callq 0x20e0
leaq 0x15210(%rip), %rdi     # 0x17cc0
xorl %esi, %esi
movl $0x18, %edx
callq 0x20e0
leaq 0x151fd(%rip), %rax     # 0x17cc0
movq %rax, 0x1518e(%rip)     # 0x17c58
leaq 0x151ef(%rip), %rdi     # 0x17cc0
leaq 0xb6c8(%rip), %rsi      # 0xe1a0
callq 0x2350
leaq 0x151dc(%rip), %rdi     # 0x17cc0
leaq 0xb7b5(%rip), %rsi      # 0xe2a0
callq 0x2350
leaq 0x151c9(%rip), %rdi     # 0x17cc0
leaq 0xb762(%rip), %rsi      # 0xe260
callq 0x2350
leaq 0x151b6(%rip), %rdi     # 0x17cc0
leaq 0xb70f(%rip), %rsi      # 0xe220
callq 0x2350
leaq 0x151a3(%rip), %rdi     # 0x17cc0
leaq 0xb7bc(%rip), %rsi      # 0xe2e0
callq 0x2350
leaq 0x15190(%rip), %rdi     # 0x17cc0
leaq 0xb7e9(%rip), %rsi      # 0xe320
callq 0x2350
leaq 0x1517d(%rip), %rdi     # 0x17cc0
leaq 0xb816(%rip), %rsi      # 0xe360
callq 0x2350
leaq 0x1516a(%rip), %rdi     # 0x17cc0
leaq 0xb683(%rip), %rsi      # 0xe1e0
callq 0x2350
movb $0x1, %al
cmpq $0x0, 0x150bc(%rip)     # 0x17c28
movb %al, -0x22(%rbp)
jne 0x2b89
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x150a9(%rip)     # 0x17c28
cmpq $0x0, %rax
setne %al
movb %al, -0x22(%rbp)
movb -0x22(%rbp), %al
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, (%rcx)
movb %al, -0x23(%rbp)
je 0x2bd8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2d, %ecx
movb %al, -0x23(%rbp)
jne 0x2bd8
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x23(%rbp)
movb -0x23(%rbp), %al
testb $0x1, %al
jne 0x2be4
jmp 0x2c85
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x2c23
movq -0x18(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x2c23
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x2c85
movb $0x0, -0x21(%rbp)
movq -0x18(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x24(%rbp)
je 0x2c58
movq -0x18(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x18(%rbp)
movb (%rax), %al
movb %al, -0x21(%rbp)
movsbl %al, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x24(%rbp)
movb -0x24(%rbp), %al
testb $0x1, %al
jne 0x2c61
jmp 0x2c63
jmp 0x2c27
movq $0x0, -0x20(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x2ba1
cmpl $0x0, -0x8(%rbp)
jge 0x2c90
callq 0x2a50
leaq 0x83a8(%rip), %rdi      # 0xb03f
callq 0x25a0
leaq 0x14f8d(%rip), %rdi     # 0x17c30
callq 0x2fb0
leaq 0x13719(%rip), %rdi     # 0x163c8
addq $0x2c, %rdi
callq 0x9980
leaq 0x13771(%rip), %rdi     # 0x16430
xorl %esi, %esi
leaq 0x837f(%rip), %rdx      # 0xb047
callq 0x8170
leaq 0x1375c(%rip), %rdi     # 0x16430
movl $0x1, %esi
leaq 0x8375(%rip), %rdx      # 0xb055
callq 0x8170
leaq 0x147ec(%rip), %rdi     # 0x174d8
xorl %esi, %esi
leaq 0x836e(%rip), %rdx      # 0xb063
callq 0x92c0
movw $0xf7c0, 0x14f3b(%rip)  # imm = 0xF7C0
movw $0xf7c0, 0x14fac(%rip)  # imm = 0xF7C0
leaq 0x14f1d(%rip), %rdi     # 0x17c30
callq 0x60a0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq