// File: /workspace/github_c_makefile_star2_O1/aap[P]rx-0/ww1/mach.c
// Function: initmach
void
initmach(void)
{
	int i;

	memset(&ww1, 0, sizeof(ww1));
	// FF storage at 2,3,4,5,7
	ww1.ff_regs = (1<<2) | (1<<3) | (1<<4) | (1<<5) | (1<<6);
	ww1.scope = &scope;
	ww1.ptape = &ptape;

	for(i = 0; i < 4; i++){
		ptape.out_fd[i] = -1;
		ptape.in_fd[i] = -1;
	}
	ptape.out_fd[0] = open("ptp", O_RDWR | O_CREAT | O_TRUNC, 0664);
	ptape.in_fd[0] = open("ptr", O_RDONLY);
	ptape.in_fd[1] = open("petr", O_RDONLY);
	ptape.out_fd[2] = open("/tmp/fl", O_RDWR);
	ptape.eu.read = ptape_read;
	ptape.eu.record = ptape_record;
	ptape.eu.init = ptape_init;
	ptape.eu.stop = ptape_stop;

	scope.eu.read = scope_read;
	scope.eu.record = scope_record;
	scope.eu.init = scope_init;
	scope.eu.stop = scope_stop;

	ww1.pc = 040;

	FILE *mf;
	mf = mustopen("out.mem", "r");
	if(mf){
		readmem(&ww1, mf);
		fclose(mf);
	}
	mf = fopen("out.sym", "r");
	if(mf){
		readsyms(mf);
		fclose(mf);
	}


/*
	// shift test
	ww1.ac = 01234;
	ww1.core[0100] = 0155003;
*/
/*
	// multiplication test
	ww1.ac = 077777;
	ww1.core[01000] = 077777;
	ww1.core[0100] = 0145000;
*/
/*
	// division test
	ww1.ac = 036000;
	ww1.core[01000] = 060000;
	ww1.core[0100] = 0151000;
	ww1.core[0101] = 0154017;
*/
/*
	// sf test
	ww1.ac = 052000 >> 2;
	ww1.core[01000] = 0177777;
	ww1.core[0100] = 0165000;
*/


	scope.fd = dial("localhost", 3400);


/*
	// hardcoded? nice!
	ww1.console_fd = open("/dev/pts/19", O_RDWR);
	if(ww1.console_fd >= 0)
		threadcreate(consthread, &ww1);
*/

	cmdchan = chancreate(sizeof(Msg), 1);
	threadcreate(simthread, &ww1);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
pushq %rax
leaq 0x90a0(%rip), %rdi      # 0xf5d0
movl $0x10f8, %edx           # imm = 0x10F8
xorl %esi, %esi
callq 0x2140
movl $0x7c, 0x90a2(%rip)     # 0xf5e8
leaq 0xa1fb(%rip), %rax      # 0x10748
movq %rax, 0xa15c(%rip)      # 0x106b0
leaq 0xa225(%rip), %rax      # 0x10780
movq %rax, 0xa156(%rip)      # 0x106b8
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa23a(%rip)     # 0x107a8
movdqu %xmm0, 0xa242(%rip)     # 0x107b8
leaq 0xef0(%rip), %rdi       # 0x746d
movl $0x242, %esi            # imm = 0x242
movl $0x1b4, %edx            # imm = 0x1B4
xorl %eax, %eax
callq 0x2310
movl %eax, 0xa214(%rip)      # 0x107a8
leaq 0xed6(%rip), %rdi       # 0x7471
xorl %esi, %esi
xorl %eax, %eax
callq 0x2310
movl %eax, 0xa20e(%rip)      # 0x107b8
leaq 0xec4(%rip), %rdi       # 0x7475
xorl %esi, %esi
xorl %eax, %eax
callq 0x2310
movl %eax, 0xa1fc(%rip)      # 0x107bc
leaq 0xeb3(%rip), %rdi       # 0x747a
movl $0x2, %esi
xorl %eax, %eax
callq 0x2310
movl %eax, 0xa1d7(%rip)      # 0x107b0
leaq -0x1e4e(%rip), %rax     # 0x4792
movq %rax, 0xa1b9(%rip)      # 0x107a0
leaq -0x1ef2(%rip), %rax     # 0x46fc
movq %rax, 0xa1a3(%rip)      # 0x10798
leaq -0x1f43(%rip), %rax     # 0x46b9
movq %rax, 0xa185(%rip)      # 0x10788
leaq -0x1f1a(%rip), %rax     # 0x46f0
movq %rax, 0xa17f(%rip)      # 0x10790
leaq -0x1f65(%rip), %rax     # 0x46b3
movq %rax, 0xa149(%rip)      # 0x10768
leaq -0x2000(%rip), %rax     # 0x4626
movq %rax, 0xa133(%rip)      # 0x10760
leaq -0x2020(%rip), %rax     # 0x4614
movq %rax, 0xa115(%rip)      # 0x10750
leaq -0x2028(%rip), %rax     # 0x461a
movq %rax, 0xa10f(%rip)      # 0x10758
movw $0x20, 0x8f8e(%rip)     # 0xf5e0
leaq 0xe29(%rip), %rdi       # 0x7482
leaq 0xdaa(%rip), %rsi       # 0x740a
callq 0x2720
testq %rax, %rax
je 0x6684
movq %rax, %rbx
leaq 0x8f5c(%rip), %rdi      # 0xf5d0
movq %rax, %rsi
callq 0x48b1
movq %rbx, %rdi
callq 0x20f0
leaq 0xdff(%rip), %rdi       # 0x748a
leaq 0xd78(%rip), %rsi       # 0x740a
callq 0x2320
testq %rax, %rax
je 0x66af
movq %rax, %rbx
movq %rax, %rdi
callq 0x497c
movq %rbx, %rdi
callq 0x20f0
leaq 0xddc(%rip), %rdi       # 0x7492
movl $0xd48, %esi            # imm = 0xD48
callq 0x390a
movl %eax, 0xa0aa(%rip)      # 0x10770
movl $0x8, %edi
movl $0x1, %esi
callq 0x3e7b
movq %rax, 0xa05c(%rip)      # 0x10738
leaq -0x1b23(%rip), %rdi     # 0x4bc0
leaq 0x8ee6(%rip), %rsi      # 0xf5d0
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x3c7c