// File: /workspace/github_c_makefile_star2_O3/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, %rbx
movl %edi, %r14d
leaq 0x96ebd(%rip), %rdi     # 0x99f00
movl $0x90, %edx
xorl %esi, %esi
callq 0x2130
xorps %xmm0, %xmm0
movups %xmm0, 0x96f3f(%rip)    # 0x99f98
leaq 0x96f30(%rip), %rax     # 0x99f90
movq %rax, 0x96ec1(%rip)     # 0x99f28
leaq 0x1017a(%rip), %rcx     # 0x131e8
movq %rcx, 0x96f1b(%rip)     # 0x99f90
movq $0x0, 0x10168(%rip) # 0x131e8
movq %rcx, %rdx
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x3080
leaq 0x10216(%rip), %rcx     # 0x132a8
movq %rcx, (%rdx)
movq $0x0, 0x10208(%rip) # 0x132a8
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x30a0
leaq 0x101b6(%rip), %rax     # 0x13268
movq %rax, (%rcx)
movq $0x0, 0x101a8(%rip) # 0x13268
leaq 0x96ec9(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x30c7
leaq 0x1014f(%rip), %rcx     # 0x13228
movq %rcx, (%rax)
movq $0x0, 0x10141(%rip) # 0x13228
leaq 0x96ea2(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x30ee
leaq 0x101e8(%rip), %rcx     # 0x132e8
movq %rcx, (%rax)
movq $0x0, 0x101da(%rip) # 0x132e8
leaq 0x96e7b(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x3115
leaq 0x10201(%rip), %rcx     # 0x13328
movq %rcx, (%rax)
movq $0x0, 0x101f3(%rip) # 0x13328
movl $0x456, 0x10251(%rip)   # imm = 0x456
leaq -0x84d(%rip), %rax      # 0x28f9
movq %rax, 0x1024b(%rip)     # 0x13398
cmpq $0x0, 0x96da3(%rip)     # 0x99ef8
jne 0x3161
movq (%rbx), %rax
movq %rax, 0x96d97(%rip)     # 0x99ef8
leaq 0x8(%rbx), %rax
leal -0x1(%r14), %ecx
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
je 0x328e
movq 0xfe7b(%rip), %rsi      # 0x12ff8
movq (%rsi), %r12
movl $0x2b5c, %r15d          # imm = 0x2B5C
xorl %ebp, %ebp
leaq 0x4fd8(%rip), %r13      # 0x8167
cmpb $0x2d, (%rdx)
jne 0x32a6
leaq 0x1(%rdx), %rdi
movzbl 0x1(%rdx), %esi
cmpl $0x2d, %esi
je 0x31b4
movq %rax, %rbx
movl %ecx, %r14d
testl %esi, %esi
jne 0x31c4
jmp 0x32a6
cmpb $0x0, 0x2(%rdx)
je 0x3298
movq %rax, %rbx
movl %ecx, %r14d
incq %rdi
movzbl %sil, %eax
cmpl $0x6f, %eax
jg 0x3201
cmpl $0x64, %eax
je 0x3231
cmpl $0x6c, %eax
jne 0x326b
cmpb $0x0, (%rdi)
jne 0x31f7
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x3359
addq $0x8, %rbx
decl %r14d
callq 0x22b0
movl %eax, %r15d
jmp 0x3268
cmpl $0x73, %eax
je 0x3248
cmpl $0x70, %eax
jne 0x326b
cmpb $0x0, (%rdi)
jne 0x3224
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x3359
addq $0x8, %rbx
decl %r14d
callq 0x22b0
movl %eax, 0x10161(%rip)     # 0x13390
jmp 0x3268
movq %r12, 0x10148(%rip)     # 0x13380
leaq -0x945(%rip), %rax      # 0x28fa
movq %rax, 0x10152(%rip)     # 0x13398
jmp 0x326b
cmpb $0x0, (%rdi)
jne 0x3261
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x3359
addq $0x8, %rbx
decl %r14d
callq 0x22b0
movl %eax, %ebp
movq %r13, %rdi
movb (%rdi), %sil
testb %sil, %sil
jne 0x31c4
leaq 0x8(%rbx), %rax
leal -0x1(%r14), %ecx
movq 0x8(%rbx), %rdx
testq %rdx, %rdx
jne 0x318f
jmp 0x32a6
xorl %ebp, %ebp
movl $0x2b5c, %r15d          # imm = 0x2B5C
jmp 0x32a6
addl $-0x2, %r14d
addq $0x10, %rbx
movl %r14d, %ecx
movq %rbx, %rax
testl %ecx, %ecx
jle 0x3359
movq (%rax), %rax
movq %rax, 0x100d0(%rip)     # 0x13388
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x96c27(%rip)     # 0x99ef0
leaq 0x96c20(%rip), %r14     # 0x99ef0
leaq 0x4ec3(%rip), %rdi      # 0x819a
callq 0x2bfc
leaq 0x1612d(%rip), %rbx     # 0x19410
movq %rbx, %rdi
callq 0x3c2c
movq %r14, 0x1611e(%rip)     # 0x19410
leaq 0x96c07(%rip), %r14     # 0x99f00
movq %r14, %rdi
callq 0x420b
leaq 0x160cc(%rip), %rdi     # 0x193d4
callq 0x6f1f
movq %rbx, %rdi
callq 0x3ff9
movq %rbx, %rdi
movl %r15d, %esi
callq 0x4010
movw $0x0, 0x96be5(%rip)     # 0x99f0e
movl %ebp, 0x96c11(%rip)     # 0x99f40
movw $0x1ff, 0x10068(%rip)   # imm = 0x1FF
movq %r14, %rdi
callq 0x6313
movq %rbx, %rdi
callq 0x3dc0
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x2f87
nop