// File: /workspace/github_c_makefile_star2_O0/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
subq $0x10, %rsp
leaq 0xa1a1(%rip), %rdi      # 0x11600
xorl %esi, %esi
movl $0x10f8, %edx           # imm = 0x10F8
callq 0x2140
movl $0x7c, 0xa1a3(%rip)     # 0x11618
leaq 0xb2fc(%rip), %rax      # 0x12778
movq %rax, 0xb25d(%rip)      # 0x126e0
leaq 0xb326(%rip), %rax      # 0x127b0
movq %rax, 0xb257(%rip)      # 0x126e8
movl $0x0, -0x4(%rbp)
cmpl $0x4, -0x4(%rbp)
jge 0x74cf
movslq -0x4(%rbp), %rcx
leaq 0xb307(%rip), %rax      # 0x127b0
movl $0xffffffff, 0x28(%rax,%rcx,4) # imm = 0xFFFFFFFF
movslq -0x4(%rbp), %rcx
leaq 0xb2f4(%rip), %rax      # 0x127b0
movl $0xffffffff, 0x38(%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x7498
leaq 0x2061(%rip), %rdi      # 0x9537
movl $0x242, %esi            # imm = 0x242
movl $0x1b4, %edx            # imm = 0x1B4
movb $0x0, %al
callq 0x2320
movl %eax, 0xb2eb(%rip)      # 0x127d8
leaq 0x2047(%rip), %rdi      # 0x953b
xorl %esi, %esi
movb $0x0, %al
callq 0x2320
movl %eax, 0xb2e5(%rip)      # 0x127e8
leaq 0x2035(%rip), %rdi      # 0x953f
xorl %esi, %esi
movb $0x0, %al
callq 0x2320
movl %eax, 0xb2d3(%rip)      # 0x127ec
leaq 0x2024(%rip), %rdi      # 0x9544
movl $0x2, %esi
movb $0x0, %al
callq 0x2320
movl %eax, 0xb2ae(%rip)      # 0x127e0
leaq -0x2219(%rip), %rax     # 0x5320
movq %rax, 0xb290(%rip)      # 0x127d0
leaq -0x2317(%rip), %rax     # 0x5230
movq %rax, 0xb27a(%rip)      # 0x127c8
leaq -0x23d5(%rip), %rax     # 0x5180
movq %rax, 0xb25c(%rip)      # 0x127b8
leaq -0x2353(%rip), %rax     # 0x5210
movq %rax, 0xb256(%rip)      # 0x127c0
leaq -0x2401(%rip), %rax     # 0x5170
movq %rax, 0xb220(%rip)      # 0x12798
leaq -0x252f(%rip), %rax     # 0x5050
movq %rax, 0xb20a(%rip)      # 0x12790
leaq -0x256d(%rip), %rax     # 0x5020
movq %rax, 0xb1ec(%rip)      # 0x12780
leaq -0x256b(%rip), %rax     # 0x5030
movq %rax, 0xb1e6(%rip)      # 0x12788
movw $0x20, 0xa065(%rip)     # 0x11610
leaq 0x1f9a(%rip), %rdi      # 0x954c
leaq 0x1f01(%rip), %rsi      # 0x94ba
callq 0x2650
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x75e2
movq -0x10(%rbp), %rsi
leaq 0xa02c(%rip), %rdi      # 0x11600
callq 0x5540
movq -0x10(%rbp), %rdi
callq 0x20d0
leaq 0x1f6b(%rip), %rdi      # 0x9554
leaq 0x1eca(%rip), %rsi      # 0x94ba
callq 0x2330
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x7612
movq -0x10(%rbp), %rdi
callq 0x5690
movq -0x10(%rbp), %rdi
callq 0x20d0
leaq 0x1f43(%rip), %rdi      # 0x955c
movl $0xd48, %esi            # imm = 0xD48
callq 0x3b50
movl %eax, 0xb177(%rip)      # 0x127a0
movl $0x8, %edi
movl $0x1, %esi
callq 0x4430
movq %rax, 0xb129(%rip)      # 0x12768
leaq -0x1bd6(%rip), %rdi     # 0x5a70
leaq 0x9fb3(%rip), %rsi      # 0x11600
callq 0x4140
addq $0x10, %rsp
popq %rbp
retq
nopl (%rax,%rax)