// File: /workspace/github_c_makefile_star2_O3/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 0x92fc(%rip), %rdi      # 0xf5d0
movl $0x10f8, %edx           # imm = 0x10F8
xorl %esi, %esi
callq 0x2140
movl $0x7c, 0x92fe(%rip)     # 0xf5e8
leaq 0xa457(%rip), %rax      # 0x10748
movq %rax, 0xa3b8(%rip)      # 0x106b0
leaq 0xa481(%rip), %rax      # 0x10780
movq %rax, 0xa3b2(%rip)      # 0x106b8
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa496(%rip)     # 0x107a8
movdqu %xmm0, 0xa49e(%rip)     # 0x107b8
leaq 0x114c(%rip), %rdi      # 0x746d
movl $0x242, %esi            # imm = 0x242
movl $0x1b4, %edx            # imm = 0x1B4
xorl %eax, %eax
callq 0x2300
movl %eax, 0xa470(%rip)      # 0x107a8
leaq 0x1132(%rip), %rdi      # 0x7471
xorl %esi, %esi
xorl %eax, %eax
callq 0x2300
movl %eax, 0xa46a(%rip)      # 0x107b8
leaq 0x1120(%rip), %rdi      # 0x7475
xorl %esi, %esi
xorl %eax, %eax
callq 0x2300
movl %eax, 0xa458(%rip)      # 0x107bc
leaq 0x110f(%rip), %rdi      # 0x747a
movl $0x2, %esi
xorl %eax, %eax
callq 0x2300
movl %eax, 0xa433(%rip)      # 0x107b0
leaq -0x1c59(%rip), %rax     # 0x472b
movq %rax, 0xa415(%rip)      # 0x107a0
leaq -0x1cfd(%rip), %rax     # 0x4695
movq %rax, 0xa3ff(%rip)      # 0x10798
leaq -0x1d4e(%rip), %rax     # 0x4652
movq %rax, 0xa3e1(%rip)      # 0x10788
leaq -0x1d25(%rip), %rax     # 0x4689
movq %rax, 0xa3db(%rip)      # 0x10790
leaq -0x1d70(%rip), %rax     # 0x464c
movq %rax, 0xa3a5(%rip)      # 0x10768
leaq -0x1e05(%rip), %rax     # 0x45c5
movq %rax, 0xa38f(%rip)      # 0x10760
leaq -0x1e25(%rip), %rax     # 0x45b3
movq %rax, 0xa371(%rip)      # 0x10750
leaq -0x1e2d(%rip), %rax     # 0x45b9
movq %rax, 0xa36b(%rip)      # 0x10758
movw $0x20, 0x91ea(%rip)     # 0xf5e0
leaq 0x1085(%rip), %rdi      # 0x7482
leaq 0x1006(%rip), %rsi      # 0x740a
callq 0x2600
testq %rax, %rax
je 0x6428
movq %rax, %rbx
leaq 0x91b8(%rip), %rdi      # 0xf5d0
movq %rax, %rsi
callq 0x4853
movq %rbx, %rdi
callq 0x20f0
leaq 0x105b(%rip), %rdi      # 0x748a
leaq 0xfd4(%rip), %rsi       # 0x740a
callq 0x2310
testq %rax, %rax
je 0x6453
movq %rax, %rbx
movq %rax, %rdi
callq 0x4922
movq %rbx, %rdi
callq 0x20f0
leaq 0x1038(%rip), %rdi      # 0x7492
movl $0xd48, %esi            # imm = 0xD48
callq 0x37b2
movl %eax, 0xa306(%rip)      # 0x10770
movl $0x8, %edi
movl $0x1, %esi
callq 0x3e3b
movq %rax, 0xa2b8(%rip)      # 0x10738
leaq -0x1916(%rip), %rdi     # 0x4b71
leaq 0x9142(%rip), %rsi      # 0xf5d0
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x3c40