// File: /workspace/github_c_makefile_star2_O1/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 0x96d4f(%rip), %rdi     # 0x99f00
movl $0x90, %edx
xorl %esi, %esi
callq 0x2130
xorps %xmm0, %xmm0
movups %xmm0, 0x96dc9(%rip)    # 0x99f90
movq $0x0, 0x96dce(%rip) # 0x99fa0
leaq 0x96db7(%rip), %rax     # 0x99f90
movq %rax, 0x96d48(%rip)     # 0x99f28
movq %rax, %rcx
movq (%rax), %rax
testq %rax, %rax
jne 0x31e0
leaq 0xfff6(%rip), %rax      # 0x131e8
movq %rax, (%rcx)
movq $0x0, 0xffe8(%rip) # 0x131e8
leaq 0x96d89(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x3207
leaq 0x1008f(%rip), %rcx     # 0x132a8
movq %rcx, (%rax)
movq $0x0, 0x10081(%rip) # 0x132a8
leaq 0x96d62(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x322e
leaq 0x10028(%rip), %rcx     # 0x13268
movq %rcx, (%rax)
movq $0x0, 0x1001a(%rip) # 0x13268
leaq 0x96d3b(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x3255
leaq 0xffc1(%rip), %rcx      # 0x13228
movq %rcx, (%rax)
movq $0x0, 0xffb3(%rip) # 0x13228
leaq 0x96d14(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x327c
leaq 0x1005a(%rip), %rcx     # 0x132e8
movq %rcx, (%rax)
movq $0x0, 0x1004c(%rip) # 0x132e8
leaq 0x96ced(%rip), %rcx     # 0x99f90
movq %rcx, %rax
movq (%rcx), %rcx
testq %rcx, %rcx
jne 0x32a3
leaq 0x10073(%rip), %rcx     # 0x13328
movq %rcx, (%rax)
movq $0x0, 0x10065(%rip) # 0x13328
movl $0x456, 0x100c3(%rip)   # imm = 0x456
leaq -0x87b(%rip), %rax      # 0x2a59
movq %rax, 0x100bd(%rip)     # 0x13398
cmpq $0x0, 0x96c15(%rip)     # 0x99ef8
jne 0x32ef
movq (%r14), %rax
movq %rax, 0x96c09(%rip)     # 0x99ef8
movq 0xfd02(%rip), %rax      # 0x12ff8
movq (%rax), %r13
movl $0x0, 0x4(%rsp)
movl $0x2b5c, (%rsp)         # imm = 0x2B5C
leaq 0x4e58(%rip), %rbp      # 0x8167
leaq 0x8(%r14), %r12
leal -0x1(%r15), %ebx
movq 0x8(%r14), %rdi
testq %rdi, %rdi
je 0x343d
cmpb $0x2d, (%rdi)
jne 0x343d
movzbl 0x1(%rdi), %eax
cmpl $0x2d, %eax
je 0x333f
testl %eax, %eax
jne 0x3349
jmp 0x343d
cmpb $0x0, 0x2(%rdi)
je 0x342b
incq %rdi
movb (%rdi), %al
testb %al, %al
movl 0x4(%rsp), %r14d
movl (%rsp), %r15d
je 0x3419
incq %rdi
movzbl %al, %eax
cmpl $0x6f, %eax
jg 0x339b
cmpl $0x64, %eax
je 0x33cb
cmpl $0x6c, %eax
jne 0x3406
cmpb $0x0, (%rdi)
jne 0x3391
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x34f5
addq $0x8, %r12
decl %ebx
callq 0x22b0
movl %eax, %r15d
jmp 0x3403
cmpl $0x73, %eax
je 0x33e2
cmpl $0x70, %eax
jne 0x3406
cmpb $0x0, (%rdi)
jne 0x33be
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x34f5
addq $0x8, %r12
decl %ebx
callq 0x22b0
movl %eax, 0xffc7(%rip)      # 0x13390
jmp 0x3403
movq %r13, 0xffae(%rip)      # 0x13380
leaq -0x97f(%rip), %rax      # 0x2a5a
movq %rax, 0xffb8(%rip)      # 0x13398
jmp 0x3406
cmpb $0x0, (%rdi)
jne 0x33fb
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x34f5
addq $0x8, %r12
decl %ebx
callq 0x22b0
movl %eax, %r14d
movq %rbp, %rdi
movb (%rdi), %al
testb %al, %al
jne 0x335f
movl %r15d, (%rsp)
movl %r14d, 0x4(%rsp)
movb $0x1, %al
movl %ebx, %r15d
movq %r12, %r14
testb %al, %al
jne 0x330f
jmp 0x343d
addl $-0x2, %r15d
addq $0x10, %r14
xorl %eax, %eax
movl %r15d, %ebx
movq %r14, %r12
jmp 0x341b
testl %ebx, %ebx
jle 0x34f5
movq (%r12), %rax
movq %rax, 0xff38(%rip)      # 0x13388
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x96a8f(%rip)     # 0x99ef0
leaq 0x96a88(%rip), %rbx     # 0x99ef0
leaq 0x4d2b(%rip), %rdi      # 0x819a
callq 0x2d69
leaq 0x15f95(%rip), %r14     # 0x19410
movq %r14, %rdi
callq 0x3def
movq %rbx, 0x15f86(%rip)     # 0x19410
leaq 0x96a6f(%rip), %r15     # 0x99f00
movq %r15, %rdi
callq 0x442f
leaq 0x15f34(%rip), %rdi     # 0x193d4
callq 0x7023
movq %r14, %rdi
callq 0x421d
movq %r14, %rdi
movl (%rsp), %esi
callq 0x4234
movw $0x0, 0x96a4d(%rip)     # 0x99f0e
movl 0x4(%rsp), %eax
movl %eax, 0x96a75(%rip)     # 0x99f40
movw $0x1ff, 0xfecc(%rip)    # imm = 0x1FF
movq %r15, %rdi
callq 0x641c
movq %r14, %rdi
callq 0x3fca
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x30f5
nop