// File: /workspace/github_c_makefile_star2_O2/calmopyrin[P]tedplay/Tedmem.cpp
// Function: TED::memin(void*)
void TED::memin(void *img)
{

	// this is ugly :-P
   	fread(Ram,RAMSIZE,1,(FILE *) img);

	fread(&RAMenable,sizeof(RAMenable),1,(FILE *) img);
	fread(&t1start,sizeof(t1start),1, (FILE *) img);
	fread(&t1on,sizeof(t1on),1, (FILE *) img);
	fread(&t2on,sizeof(t2on),1, (FILE *) img);
	fread(&t3on,sizeof(t3on),1, (FILE *) img);
	fread(&timer1,sizeof(timer1),1, (FILE *) img);
	fread(&timer2,sizeof(timer2),1, (FILE *) img);
	fread(&timer3,sizeof(timer3),1, (FILE *) img);
	fread(&beamx,sizeof(beamx),1, (FILE *) img);
	fread(&beamy,sizeof(beamy),1, (FILE *) img);
	//fread(&x,sizeof(x),1, (FILE *) img);
	fread(&irqline,sizeof(irqline),1, (FILE *) img);
	fread(&crsrpos,sizeof(crsrpos),1, (FILE *) img);
	fread(&scrattr,sizeof(scrattr),1, (FILE *) img);
	fread(&tmp,sizeof(tmp),1, (FILE *) img);
	fread(&nrwscr,sizeof(nrwscr),1, (FILE *) img);
	fread(&hshift,sizeof(hshift),1, (FILE *) img);
	fread(&vshift,sizeof(vshift),1, (FILE *) img);
	fread(&fltscr,sizeof(fltscr),1, (FILE *) img);
	fread(&mcol,sizeof(mcol),1, (FILE *) img);
	fread(chrbuf,40,1, (FILE *) img);
	fread(clrbuf,40,1, (FILE *) img);
	fread(&charrom,sizeof(charrom),1, (FILE *) img);
	fread(&charbank,sizeof(charbank),1, (FILE *) img);
//	fread(&TEDfreq1,sizeof(TEDfreq1),1, (FILE *) img);
//	fread(&TEDfreq2,sizeof(TEDfreq2),1, (FILE *) img);
//	fread(&TEDVolume,sizeof(TEDVolume),1, (FILE *) img);
//	fread(&TEDDA,sizeof(TEDDA),1, (FILE *) img);
	fread(&framecol,sizeof(framecol),1, (FILE *) img);

	for (int i=0; i<5; i++)
		writeSoundReg(i, Ram[0xFF0E + i]);
	beamy=0;
	beamx=0;
	scrptr=&(screen[0]);
	charrambank=Ram+charbank;
	charrombank=&(RomHi[0][charbank & 0x3C00]);
	(charrom) ? cset = charrombank : cset = charrambank;

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x45fc0(%rdi), %r14
pushq $0x1
popq %r12
movl $0x10000, %esi          # imm = 0x10000
movq %r14, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x18(%rbx), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fd0(%rbx), %rdi
pushq $0x4
popq %r13
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fc0(%rbx), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fc1(%rbx), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fc2(%rbx), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fc4(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fc8(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x65fcc(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x81c(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x820(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6184(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x45fa8(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6130(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0x1a808(%rip), %rdi     # 0x254c8
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6024(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb601c(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6020(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6028(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb618a(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
movq 0xb60f0(%rbx), %rdi
pushq $0x28
popq %rbp
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
movq 0xb60f8(%rbx), %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6120(%rbx), %rdi
movq %r12, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6134(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
leaq 0xb6138(%rbx), %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %r15, %rcx
callq 0x32d0
xorl %r15d, %r15d
cmpq $0x5, %r15
je 0xadc5
movzbl 0x55ece(%rbx,%r15), %edx
movq %rbx, %rdi
movl %r15d, %esi
callq 0xb8f6
incq %r15
jmp 0xada6
andq $0x0, 0x81c(%rbx)
leaq 0x824(%rbx), %rax
movq %rax, 0xb6160(%rbx)
movl 0xb6134(%rbx), %eax
cltq
addq %rax, %r14
movq %r14, 0xb6150(%rbx)
andl $0x3c00, %eax           # imm = 0x3C00
addq %rbx, %rax
addq $0x55fc0, %rax          # imm = 0x55FC0
movq %rax, 0xb6148(%rbx)
cmpb $0x0, 0xb6120(%rbx)
cmovneq %rax, %r14
movq %r14, 0xb6198(%rbx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop