// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
movq %rsi, %r15
movq %rdi, %rbx
leaq 0x45fc0(%rdi), %r14
movl $0x10000, %esi          # imm = 0x10000
movl $0x1, %edx
movq %r14, %rdi
movq %r15, %rcx
callq 0x32e0
leaq 0x18(%rbx), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fd0(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fc0(%rbx), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fc1(%rbx), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fc2(%rbx), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fc4(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fc8(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x65fcc(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x81c(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x820(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6184(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x45fa8(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6130(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0x1a406(%rip), %rdi     # 0x254b8
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6024(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb601c(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6020(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6028(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb618a(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
movq 0xb60f0(%rbx), %rdi
movl $0x28, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
movq 0xb60f8(%rbx), %rdi
movl $0x28, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6120(%rbx), %rdi
movl $0x1, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6134(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
leaq 0xb6138(%rbx), %rdi
movl $0x4, %esi
movl $0x1, %edx
movq %r15, %rcx
callq 0x32e0
xorl %r15d, %r15d
movzbl 0x55ece(%rbx,%r15), %edx
movq %rbx, %rdi
movl %r15d, %esi
callq 0xbdcc
incq %r15
cmpq $0x5, %r15
jne 0xb1c1
movq $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)
popq %rbx
popq %r14
popq %r15
retq