// File: /workspace/github_c_makefile_star2_O2/aap[P]pdp11/tv11.c
// Function: main
int
main(int argc, char *argv[])
{
	int lport;
	uint32 sleep;

	memset(&cpu, 0, sizeof(cpu));
	memset(&bus, 0, sizeof(Bus));
	cpu.bus = &bus;
	busadddev(&bus, &membusdev);
#ifndef KD11Bp
	busadddev(&bus, &kwbusdev);
	busadddev(&bus, &klbusdev);
#endif
	busadddev(&bus, &kebusdev);
	busadddev(&bus, &tvbusdev);
	busadddev(&bus, &ten11busdev);

	port = 1110;
	lport = 11100;
	sleep = 0;
	debug = quiet;
	ARGBEGIN{
	case 'p':
		port = atoi(EARGF(usage()));
		break;
	case 'l':
		lport = atoi(EARGF(usage()));
		break;
	case 's':
		sleep = atoi(EARGF(usage()));
		break;
	case 'd':
		logfile = stderr;
		debug = log;
		break;
	}ARGEND;

	if(argc < 1)
		usage();

	host = argv[0];
	ten11.cycle = 0;
	ten11.fd = -1;
	loadmem("mem.txt");

//	if(loadpt("maindec/MAINDEC-11-D0NA-PB.ptap"))
//	if(loadpt("maindec/MAINDEC-11-D2AA-PB.ptap"))
//		return 0;

//	cpu.r[7] = 0200;
//	cpu.sw = 0104000;

	//void eaetest(KE11 *ke);
	//eaetest(&ke11);

	inittv(&tv);
	tv.ten11 = &ten11;

	reset(&cpu);

	ttyopen(&TTYDEV.tty);

	/* start the two threads for listening for
	 * and handling TV display connections */
	handletvs(&tv);
	servetv(&tv, lport);

	//void tvtest(TV *tv, Bus *bus);
	//tvtest(&tv, &bus);

	/* wait until we get some data from the 10 */
	cpu.r[7] = 0;
	cpu.throttle = sleep;
	memory[0] = 0777;
	run(&cpu);

	closetv(&tv);

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r14
movl %edi, %r15d
leaq 0x972cc(%rip), %rdi     # 0x99f00
xorl %ebx, %ebx
movl $0x90, %edx
xorl %esi, %esi
callq 0x2130
andq $0x0, 0x97356(%rip)     # 0x99fa0
xorps %xmm0, %xmm0
movups %xmm0, 0x9733c(%rip)    # 0x99f90
leaq 0x97335(%rip), %r12     # 0x99f90
movq %r12, 0x972c6(%rip)     # 0x99f28
leaq 0x1057f(%rip), %rsi     # 0x131e8
movq %r12, %rdi
callq 0x247c
leaq 0x10630(%rip), %rsi     # 0x132a8
movq %r12, %rdi
callq 0x247c
leaq 0x105e1(%rip), %rsi     # 0x13268
movq %r12, %rdi
callq 0x247c
leaq 0x10592(%rip), %rsi     # 0x13228
movq %r12, %rdi
callq 0x247c
leaq 0x10643(%rip), %rsi     # 0x132e8
movq %r12, %rdi
callq 0x247c
leaq 0x10674(%rip), %rsi     # 0x13328
movq %r12, %rdi
callq 0x247c
movl $0x456, 0x106ca(%rip)   # imm = 0x456
leaq -0x796(%rip), %rax      # 0x2537
movq %rax, 0x106c4(%rip)     # 0x13398
cmpq $0x0, 0x9721c(%rip)     # 0x99ef8
jne 0x2ce8
movq (%r14), %rax
movq %rax, 0x97210(%rip)     # 0x99ef8
movq 0x10309(%rip), %rax     # 0x12ff8
movq (%rax), %r12
movl $0x2b5c, %ebp           # imm = 0x2B5C
leaq 0x4469(%rip), %r13      # 0x7167
leaq 0x8(%r14), %rcx
leal -0x1(%r15), %edx
movq 0x8(%r14), %rsi
testq %rsi, %rsi
je 0x2dfe
cmpb $0x2d, (%rsi)
jne 0x2dfe
leaq 0x1(%rsi), %rdi
movzbl 0x1(%rsi), %eax
cmpl $0x2d, %eax
je 0x2d32
testl %eax, %eax
jne 0x2d3c
jmp 0x2dfe
cmpb $0x0, 0x2(%rsi)
je 0x2df0
movl %edx, %r15d
movq %rcx, %r14
testb %al, %al
je 0x2cfe
incq %rdi
cmpb $0x64, %al
je 0x2dd4
movzbl %al, %eax
cmpl $0x6c, %eax
je 0x2d8d
cmpl $0x73, %eax
je 0x2daf
cmpl $0x70, %eax
jne 0x2de9
cmpb $0x0, (%rdi)
jne 0x2d80
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x2eaf
addq $0x8, %r14
decl %r15d
callq 0x22b0
movl %eax, 0x10605(%rip)     # 0x13390
jmp 0x2dcf
cmpb $0x0, (%rdi)
jne 0x2da6
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x2eaf
addq $0x8, %r14
decl %r15d
callq 0x22b0
movl %eax, %ebp
jmp 0x2dcf
cmpb $0x0, (%rdi)
jne 0x2dc8
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x2eaf
addq $0x8, %r14
decl %r15d
callq 0x22b0
movl %eax, %ebx
movq %r13, %rdi
jmp 0x2de9
movq %r12, 0x105a5(%rip)     # 0x13380
leaq -0x8aa(%rip), %rax      # 0x2538
movq %rax, 0x105af(%rip)     # 0x13398
movb (%rdi), %al
jmp 0x2d42
addl $-0x2, %r15d
addq $0x10, %r14
movl %r15d, %edx
movq %r14, %rcx
testl %edx, %edx
jle 0x2eaf
movq (%rcx), %rax
movq %rax, 0x10578(%rip)     # 0x13388
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x970cf(%rip)     # 0x99ef0
leaq 0x970c8(%rip), %r15     # 0x99ef0
leaq 0x436b(%rip), %rdi      # 0x719a
callq 0x283c
leaq 0x165d5(%rip), %r14     # 0x19410
movq %r14, %rdi
callq 0x375f
movq %r15, 0x165c6(%rip)     # 0x19410
leaq 0x970af(%rip), %r15     # 0x99f00
movq %r15, %rdi
callq 0x4067
leaq 0x16574(%rip), %rdi     # 0x193d4
callq 0x6b65
movq %r14, %rdi
callq 0x3b3f
movq %r14, %rdi
movl %ebp, %esi
callq 0x3e2f
andw $0x0, 0x9708f(%rip)     # 0x99f0e
movl %ebx, 0x970bb(%rip)     # 0x99f40
movw $0x1ff, 0x10512(%rip)   # imm = 0x1FF
movq %r15, %rdi
callq 0x5ff5
movq %r14, %rdi
callq 0x390c
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2b86