// File: /workspace/github_c_makefile_star2_O2/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 0x8d59(%rip), %rdi      # 0xe5d0
movl $0x10f8, %edx           # imm = 0x10F8
xorl %esi, %esi
callq 0x2140
movl $0x7c, 0x8d5b(%rip)     # 0xe5e8
leaq 0x9eb4(%rip), %rax      # 0xf748
movq %rax, 0x9e15(%rip)      # 0xf6b0
leaq 0x9ede(%rip), %rax      # 0xf780
movq %rax, 0x9e0f(%rip)      # 0xf6b8
pushq $-0x10
popq %rcx
testq %rcx, %rcx
je 0x58c1
orl $-0x1, 0x38(%rcx,%rax)
orl $-0x1, 0x48(%rcx,%rax)
addq $0x4, %rcx
jmp 0x58ac
leaq 0xbb5(%rip), %rdi       # 0x647d
movl $0x242, %esi            # imm = 0x242
movl $0x1b4, %edx            # imm = 0x1B4
xorl %eax, %eax
callq 0x2300
movl %eax, 0x9ec9(%rip)      # 0xf7a8
leaq 0xb9b(%rip), %rdi       # 0x6481
xorl %esi, %esi
xorl %eax, %eax
callq 0x2300
movl %eax, 0x9ec3(%rip)      # 0xf7b8
leaq 0xb89(%rip), %rdi       # 0x6485
xorl %esi, %esi
xorl %eax, %eax
callq 0x2300
movl %eax, 0x9eb1(%rip)      # 0xf7bc
leaq 0xb78(%rip), %rdi       # 0x648a
pushq $0x2
popq %rsi
xorl %eax, %eax
callq 0x2300
movl %eax, 0x9e8e(%rip)      # 0xf7b0
leaq -0x1633(%rip), %rax     # 0x42f6
movq %rax, 0x9e70(%rip)      # 0xf7a0
leaq -0x16d5(%rip), %rax     # 0x4262
movq %rax, 0x9e5a(%rip)      # 0xf798
leaq -0x1723(%rip), %rax     # 0x4222
movq %rax, 0x9e3c(%rip)      # 0xf788
leaq -0x16fa(%rip), %rax     # 0x4259
movq %rax, 0x9e36(%rip)      # 0xf790
leaq -0x1745(%rip), %rax     # 0x421c
movq %rax, 0x9e00(%rip)      # 0xf768
leaq -0x17d3(%rip), %rax     # 0x419c
movq %rax, 0x9dea(%rip)      # 0xf760
leaq -0x17f0(%rip), %rax     # 0x418d
movq %rax, 0x9dcc(%rip)      # 0xf750
leaq -0x17f8(%rip), %rax     # 0x4193
movq %rax, 0x9dc6(%rip)      # 0xf758
movw $0x20, 0x8c45(%rip)     # 0xe5e0
leaq 0xaf0(%rip), %rdi       # 0x6492
leaq 0xa71(%rip), %rsi       # 0x641a
callq 0x25fc
testq %rax, %rax
je 0x59cd
movq %rax, %rbx
leaq 0x8c13(%rip), %rdi      # 0xe5d0
movq %rax, %rsi
callq 0x4419
movq %rbx, %rdi
callq 0x20f0
leaq 0xac6(%rip), %rdi       # 0x649a
leaq 0xa3f(%rip), %rsi       # 0x641a
callq 0x2310
testq %rax, %rax
je 0x59f8
movq %rax, %rbx
movq %rax, %rdi
callq 0x44c9
movq %rbx, %rdi
callq 0x20f0
leaq 0xaa3(%rip), %rdi       # 0x64a2
movl $0xd48, %esi            # imm = 0xD48
callq 0x3455
movl %eax, 0x9d61(%rip)      # 0xf770
pushq $0x8
popq %rdi
pushq $0x1
popq %rsi
callq 0x3a81
movq %rax, 0x9d17(%rip)      # 0xf738
leaq -0x1334(%rip), %rdi     # 0x46f4
leaq 0x8ba1(%rip), %rsi      # 0xe5d0
addq $0x8, %rsp
popq %rbx
popq %rbp
jmp 0x389a