// File: pelrun[P]aft/CAksFileTransfert.cpp
// Function: CAksFileTransfert::WaitTrack(CAksCommand const&)
bool CAksFileTransfert::WaitTrack(const CAksCommand &cmd)
{
	if (cmd != AksWaitTrack)
		return false;

	_transferingData = true;

	unsigned char trackNum;
	unsigned char sideNum;

	ReadWaitByte(trackNum);
	ReadWaitByte(sideNum);

	CDSKTrack fakeTrack;
	CDSKTrack *track = NULL;
	
	if (_EDSKFile != NULL)
	{
		track = _EDSKFile->GetTrack(trackNum, sideNum);
	}

	if (track == NULL)
	{
		track = &fakeTrack;
		std::cout << "Fake track reading !" << std::endl;
	}

	std::cout << "Reading T" << (int)trackNum << " S" << (int)sideNum << std::endl;

	track->TrackNumber = trackNum;
	track->SideNumber = sideNum;

	ReadWaitByte(track->SectorSize);
	ReadWaitByte(track->NbSector);
	ReadWaitByte(track->GAP3Size);
	ReadWaitByte(track->FillByte);

	std::cout << "track " << (int)track->SectorSize << " " << (int)track->NbSector << " " << (int)track->GAP3Size << " " << (int)track->FillByte << std::endl;

	track->Allocate();

	for (int s = 0; s < track->NbSector ; s++)
	{
		CDSKSector &sect = track->Sectors[s];

		ReadWaitByte(sect.Track);
		ReadWaitByte(sect.Side);
		ReadWaitByte(sect.SectorID);
		ReadWaitByte(sect.SectorSize);
		ReadWaitByte(sect.FDCStatus1);
		ReadWaitByte(sect.FDCStatus2);
		ReadWaitWord(sect.DataSize);

		sect.DisplayInfo(std::cout);

		sect.Allocate();

		ReadWaitBuffer(sect.Data, sect.GetDataSize());

		sect.Update();
	}

	track->Update();

	track->DisplayInfo(std::cout);

	return true;
}

// Assembly:
subq $0xf8, %rsp
movq %rdi, 0xe8(%rsp)
movq %rsi, 0xe0(%rsp)
movq 0xe8(%rsp), %rax
movq %rax, 0x88(%rsp)
movq 0xe0(%rsp), %rax
cmpl $0xfa, (%rax)
je 0x68e4
movb $0x0, 0xf7(%rsp)
jmp 0x6daa
movq 0x88(%rsp), %rdi
movb $0x1, 0x40(%rdi)
leaq 0xdf(%rsp), %rsi
callq 0x75f0
movq 0x88(%rsp), %rdi
leaq 0xde(%rsp), %rsi
callq 0x75f0
leaq 0xb0(%rsp), %rdi
callq 0x8a50
movq 0x88(%rsp), %rax
movq $0x0, 0xa8(%rsp)
cmpq $0x0, 0x98(%rax)
je 0x69a3
movq 0x88(%rsp), %rax
movq 0x98(%rax), %rdi
movzbl 0xdf(%rsp), %esi
movzbl 0xde(%rsp), %edx
callq 0xa310
movq %rax, 0x80(%rsp)
jmp 0x696b
movq 0x80(%rsp), %rax
movq %rax, 0xa8(%rsp)
jmp 0x69a3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa0(%rsp)
movl %eax, 0x9c(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x8ae0
jmp 0x6dbb
cmpq $0x0, 0xa8(%rsp)
jne 0x69ed
leaq 0xb0(%rsp), %rax
movq %rax, 0xa8(%rsp)
movq 0x14603(%rip), %rdi     # 0x1afc8
leaq 0xecad(%rip), %rsi      # 0x15679
callq 0x42f0
movq %rax, 0x78(%rsp)
jmp 0x69d8
movq 0x78(%rsp), %rdi
movq 0x145c4(%rip), %rsi     # 0x1afa8
callq 0x4360
jmp 0x69eb
jmp 0x69ed
movq 0x145d4(%rip), %rdi     # 0x1afc8
leaq 0xec93(%rip), %rsi      # 0x1568e
callq 0x42f0
movq %rax, 0x70(%rsp)
jmp 0x6a07
movq 0x70(%rsp), %rdi
movzbl 0xdf(%rsp), %esi
callq 0x45f0
movq %rax, 0x68(%rsp)
jmp 0x6a20
movq 0x68(%rsp), %rdi
leaq 0xec6c(%rip), %rsi      # 0x15698
callq 0x42f0
movq %rax, 0x60(%rsp)
jmp 0x6a38
movq 0x60(%rsp), %rdi
movzbl 0xde(%rsp), %esi
callq 0x45f0
movq %rax, 0x58(%rsp)
jmp 0x6a51
movq 0x58(%rsp), %rdi
movq 0x1454b(%rip), %rsi     # 0x1afa8
callq 0x4360
jmp 0x6a64
movq 0x88(%rsp), %rdi
movb 0xdf(%rsp), %cl
movq 0xa8(%rsp), %rax
movb %cl, 0x11(%rax)
movb 0xde(%rsp), %cl
movq 0xa8(%rsp), %rax
movb %cl, 0x12(%rax)
movq 0xa8(%rsp), %rsi
addq $0x15, %rsi
callq 0x75f0
jmp 0x6aa3
movq 0x88(%rsp), %rdi
movq 0xa8(%rsp), %rsi
addq $0x16, %rsi
callq 0x75f0
jmp 0x6abe
movq 0x88(%rsp), %rdi
movq 0xa8(%rsp), %rsi
addq $0x17, %rsi
callq 0x75f0
jmp 0x6ad9
movq 0x88(%rsp), %rdi
movq 0xa8(%rsp), %rsi
addq $0x18, %rsi
callq 0x75f0
jmp 0x6af4
movq 0x144cd(%rip), %rdi     # 0x1afc8
leaq 0xeb99(%rip), %rsi      # 0x1569b
callq 0x42f0
movq %rax, 0x50(%rsp)
jmp 0x6b0e
movq 0x50(%rsp), %rdi
movq 0xa8(%rsp), %rax
movzbl 0x15(%rax), %esi
callq 0x45f0
movq %rax, 0x48(%rsp)
jmp 0x6b2b
movq 0x48(%rsp), %rdi
leaq 0xee41(%rip), %rsi      # 0x15978
callq 0x42f0
movq %rax, 0x40(%rsp)
jmp 0x6b43
movq 0x40(%rsp), %rdi
movq 0xa8(%rsp), %rax
movzbl 0x16(%rax), %esi
callq 0x45f0
movq %rax, 0x38(%rsp)
jmp 0x6b60
movq 0x38(%rsp), %rdi
leaq 0xee0c(%rip), %rsi      # 0x15978
callq 0x42f0
movq %rax, 0x30(%rsp)
jmp 0x6b78
movq 0x30(%rsp), %rdi
movq 0xa8(%rsp), %rax
movzbl 0x17(%rax), %esi
callq 0x45f0
movq %rax, 0x28(%rsp)
jmp 0x6b95
movq 0x28(%rsp), %rdi
leaq 0xedd7(%rip), %rsi      # 0x15978
callq 0x42f0
movq %rax, 0x20(%rsp)
jmp 0x6bad
movq 0x20(%rsp), %rdi
movq 0xa8(%rsp), %rax
movzbl 0x18(%rax), %esi
callq 0x45f0
movq %rax, 0x18(%rsp)
jmp 0x6bca
movq 0x18(%rsp), %rdi
movq 0x143d2(%rip), %rsi     # 0x1afa8
callq 0x4360
jmp 0x6bdd
movq 0xa8(%rsp), %rdi
callq 0x8da0
jmp 0x6bec
movl $0x0, 0x98(%rsp)
movl 0x98(%rsp), %eax
movq 0xa8(%rsp), %rcx
movzbl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x6d70
movq 0x88(%rsp), %rdi
movq 0xa8(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x98(%rsp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq 0x90(%rsp), %rsi
callq 0x75f0
jmp 0x6c4c
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x75f0
jmp 0x6c66
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x2, %rsi
callq 0x75f0
jmp 0x6c81
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x3, %rsi
callq 0x75f0
jmp 0x6c9c
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x4, %rsi
callq 0x75f0
jmp 0x6cb7
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x5, %rsi
callq 0x75f0
jmp 0x6cd2
movq 0x88(%rsp), %rdi
movq 0x90(%rsp), %rsi
addq $0x6, %rsi
callq 0x7690
jmp 0x6ced
movq 0x90(%rsp), %rdi
movq 0x142cc(%rip), %rsi     # 0x1afc8
callq 0x8550
jmp 0x6d03
movq 0x90(%rsp), %rdi
callq 0x83c0
jmp 0x6d12
movq 0x90(%rsp), %rdi
movq 0x8(%rdi), %rax
movq %rax, 0x8(%rsp)
callq 0x8440
movl %eax, 0x14(%rsp)
jmp 0x6d2e
movq 0x8(%rsp), %rsi
movq 0x88(%rsp), %rdi
movl 0x14(%rsp), %eax
movslq %eax, %rdx
callq 0x7730
jmp 0x6d49
movq 0x90(%rsp), %rdi
callq 0x8490
jmp 0x6d58
jmp 0x6d5a
movl 0x98(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x98(%rsp)
jmp 0x6bf7
movq 0xa8(%rsp), %rdi
callq 0x8f90
jmp 0x6d7f
movq 0xa8(%rsp), %rdi
movq 0x1423a(%rip), %rsi     # 0x1afc8
callq 0x9470
jmp 0x6d95
movb $0x1, 0xf7(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0x8ae0
movb 0xf7(%rsp), %al
andb $0x1, %al
addq $0xf8, %rsp
retq
movq 0xa0(%rsp), %rdi
callq 0x11ab0
nopl (%rax,%rax)