// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq 0x91f73(%rip), %rdi     # 0x950a0
xorl %esi, %esi
movl $0x90, %edx
callq 0x2130
leaq 0x91ff0(%rip), %rdi     # 0x95130
xorl %esi, %esi
movl $0x18, %edx
callq 0x2130
leaq 0x91fdd(%rip), %rax     # 0x95130
movq %rax, 0x91f6e(%rip)     # 0x950c8
leaq 0x91fcf(%rip), %rdi     # 0x95130
leaq 0xb080(%rip), %rsi      # 0xe1e8
callq 0x2470
leaq 0x91fbc(%rip), %rdi     # 0x95130
leaq 0xb12d(%rip), %rsi      # 0xe2a8
callq 0x2470
leaq 0x91fa9(%rip), %rdi     # 0x95130
leaq 0xb0da(%rip), %rsi      # 0xe268
callq 0x2470
leaq 0x91f96(%rip), %rdi     # 0x95130
leaq 0xb087(%rip), %rsi      # 0xe228
callq 0x2470
leaq 0x91f83(%rip), %rdi     # 0x95130
leaq 0xb134(%rip), %rsi      # 0xe2e8
callq 0x2470
leaq 0x91f70(%rip), %rdi     # 0x95130
leaq 0xb161(%rip), %rsi      # 0xe328
callq 0x2470
movl $0x456, 0xb35a(%rip)    # imm = 0x456
movl $0x2b5c, -0x14(%rbp)    # imm = 0x2B5C
movl $0x0, -0x18(%rbp)
leaq -0xb2b(%rip), %rax      # 0x26c0
movq %rax, 0xb346(%rip)      # 0xe538
movb $0x1, %al
cmpq $0x0, 0x91e9c(%rip)     # 0x95098
movb %al, -0x2a(%rbp)
jne 0x3219
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x91e89(%rip)     # 0x95098
cmpq $0x0, %rax
setne %al
movb %al, -0x2a(%rbp)
movb -0x2a(%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, -0x2b(%rbp)
je 0x3268
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x2d, %ecx
movb %al, -0x2b(%rbp)
jne 0x3268
movq -0x10(%rbp), %rax
movq (%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2b(%rbp)
movb -0x2b(%rbp), %al
testb $0x1, %al
jne 0x3274
jmp 0x34d8
movq -0x10(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2d, %eax
jne 0x32b6
movq -0x20(%rbp), %rax
movsbl 0x1(%rax), %eax
cmpl $0x0, %eax
jne 0x32b6
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x34d8
movb $0x0, -0x29(%rbp)
movq -0x20(%rbp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x2c(%rbp)
je 0x32eb
movq -0x20(%rbp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, -0x20(%rbp)
movb (%rax), %al
movb %al, -0x29(%rbp)
movsbl %al, %eax
cmpl $0x0, %eax
setne %al
movb %al, -0x2c(%rbp)
movb -0x2c(%rbp), %al
testb $0x1, %al
jne 0x32f7
jmp 0x34b6
movsbl -0x29(%rbp), %eax
addl $-0x64, %eax
movl %eax, %ecx
movq %rcx, -0x38(%rbp)
subl $0xf, %eax
ja 0x34b1
movq -0x38(%rbp), %rax
leaq 0x7cec(%rip), %rcx      # 0xb004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x7d49(%rip), %rax      # 0xb079
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x334a
movq -0x28(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x338b
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3377
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x3381
callq 0x3060
callq 0x2060
movq -0x48(%rbp), %rax
movq %rax, -0x40(%rbp)
jmp 0x338b
movq -0x40(%rbp), %rdi
callq 0x22b0
movl %eax, 0xb196(%rip)      # 0xe530
jmp 0x34b1
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x7ccb(%rip), %rax      # 0xb079
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x33c8
movq -0x28(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x3409
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x33f5
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x58(%rbp)
jmp 0x33ff
callq 0x3060
callq 0x2060
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x3409
movq -0x50(%rbp), %rdi
callq 0x22b0
movl %eax, -0x14(%rbp)
jmp 0x34b1
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
leaq 0x7c50(%rip), %rax      # 0xb079
movq %rax, -0x20(%rbp)
movq -0x28(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x3443
movq -0x28(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x3484
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3470
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, %rcx
addq $0x8, %rcx
movq %rcx, -0x10(%rbp)
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x347a
callq 0x3060
callq 0x2060
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
jmp 0x3484
movq -0x60(%rbp), %rdi
callq 0x22b0
movl %eax, -0x18(%rbp)
jmp 0x34b1
movq 0xab5f(%rip), %rax      # 0xdff8
movq (%rax), %rax
movq %rax, 0xb07d(%rip)      # 0xe520
leaq -0xd6a(%rip), %rax      # 0x2740
movq %rax, 0xb087(%rip)      # 0xe538
jmp 0x32ba
movq $0x0, -0x28(%rbp)
movl -0x8(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x8(%rbp)
movq -0x10(%rbp), %rax
addq $0x8, %rax
movq %rax, -0x10(%rbp)
jmp 0x3231
cmpl $0x1, -0x8(%rbp)
jge 0x34e3
callq 0x3060
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0xb037(%rip)      # 0xe528
movl $0x0, 0x91b95(%rip)     # 0x95090
movl $0xffffffff, 0x91b8f(%rip) # imm = 0xFFFFFFFF
leaq 0x7cfc(%rip), %rdi      # 0xb208
callq 0x2b70
leaq 0x11098(%rip), %rdi     # 0x145b0
callq 0x4650
leaq 0x91b6c(%rip), %rax     # 0x95090
movq %rax, 0x11085(%rip)     # 0x145b0
leaq 0x91b6e(%rip), %rdi     # 0x950a0
callq 0x57c0
leaq 0x1100a(%rip), %rdi     # 0x14548
addq $0x2c, %rdi
callq 0xa420
leaq 0x11062(%rip), %rdi     # 0x145b0
callq 0x4e60
movl -0x14(%rbp), %esi
leaq 0x11053(%rip), %rdi     # 0x145b0
callq 0x5060
movw $0x0, 0x91b43(%rip)     # 0x950ae
movl -0x18(%rbp), %eax
movl %eax, 0x91b6c(%rip)     # 0x950e0
movw $0x1ff, 0xafc3(%rip)    # imm = 0x1FF
leaq 0x91b1c(%rip), %rdi     # 0x950a0
callq 0x88b0
leaq 0x11020(%rip), %rdi     # 0x145b0
callq 0x4a60
xorl %eax, %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)