// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl (%rsi), %eax
cmpl $0xfa, %eax
jne 0x4a27
movq %rdi, %rbx
movl %eax, 0x1c(%rsp)
movb $0x1, 0x40(%rdi)
leaq 0xf(%rsp), %rsi
callq 0x4d96
leaq 0xe(%rsp), %rsi
movq %rbx, %rdi
callq 0x4d96
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x5928
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x47e8
movzbl 0xf(%rsp), %esi
movzbl 0xe(%rsp), %edx
callq 0x650c
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x4808
movq 0xf7d9(%rip), %rdi      # 0x13fc8
leaq 0x9e6b(%rip), %rsi      # 0xe661
callq 0x3270
movq %rax, %rdi
callq 0x3130
movq %r15, 0x10(%rsp)
movq 0xf7b9(%rip), %rdi      # 0x13fc8
leaq 0x9e60(%rip), %rsi      # 0xe676
callq 0x3270
movzbl 0xf(%rsp), %esi
movq %rax, %rdi
callq 0x34e0
leaq 0x9e51(%rip), %rsi      # 0xe680
movq %rax, %rdi
callq 0x3270
movzbl 0xe(%rsp), %esi
movq %rax, %rdi
callq 0x34e0
movq %rax, %rdi
callq 0x3130
movb 0xf(%rsp), %al
movq 0x10(%rsp), %rcx
movb %al, 0x11(%rcx)
movb 0xe(%rsp), %al
movb %al, 0x12(%rcx)
leaq 0x15(%rcx), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4d96
movq 0x10(%rsp), %rax
leaq 0x16(%rax), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4d96
movq 0x10(%rsp), %rax
leaq 0x17(%rax), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4d96
movq 0x10(%rsp), %rax
leaq 0x18(%rax), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x4d96
movq 0xf717(%rip), %rdi      # 0x13fc8
leaq 0x9dcb(%rip), %rsi      # 0xe683
callq 0x3270
movzbl (%rbp), %esi
movq %rax, %rdi
callq 0x34e0
leaq 0xa089(%rip), %rsi      # 0xe959
movq %rax, %rdi
callq 0x3270
movzbl (%r15), %esi
movq %rax, %rdi
callq 0x34e0
leaq 0xa06e(%rip), %rsi      # 0xe959
movq %rax, %rdi
callq 0x3270
movzbl (%r13), %esi
movq %rax, %rdi
callq 0x34e0
leaq 0xa052(%rip), %rsi      # 0xe959
movq %rax, %rdi
callq 0x3270
movzbl (%r12), %esi
movq %rax, %rdi
callq 0x34e0
movq %rax, %rdi
callq 0x3130
movq 0x10(%rsp), %rdi
callq 0x5afa
pushq $0x4
popq %r12
xorl %r14d, %r14d
movzbl (%r15), %eax
cmpq %rax, %r14
jae 0x49fe
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rbp
leaq (%r12,%rbp), %r13
addq $-0x4, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4d96
leaq (%r12,%rbp), %rsi
addq $-0x3, %rsi
movq %rbx, %rdi
callq 0x4d96
leaq (%r12,%rbp), %rsi
addq $-0x2, %rsi
movq %rbx, %rdi
callq 0x4d96
leaq (%r12,%rbp), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x4d96
leaq (%r12,%rbp), %rsi
movq %rbx, %rdi
callq 0x4d96
leaq (%r12,%rbp), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x4d96
leaq (%r12,%rbp), %rsi
addq $0x2, %rsi
movq %rbx, %rdi
callq 0x4dd8
movq %r13, %rdi
movq 0xf606(%rip), %rsi      # 0x13fc8
callq 0x554e
movq %r13, %rdi
callq 0x5498
movq 0x4(%rbp,%r12), %rbp
movq %r13, %rdi
callq 0x54d4
movslq %eax, %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4e46
movq %r13, %rdi
callq 0x54e8
incq %r14
addq $0x20, %r12
jmp 0x4935
movq 0x10(%rsp), %rdi
callq 0x5baa
movq 0xf5b9(%rip), %rsi      # 0x13fc8
movq 0x10(%rsp), %rdi
callq 0x5e4e
leaq 0x20(%rsp), %rdi
callq 0x595c
movl 0x1c(%rsp), %eax
cmpl $0xfa, %eax
sete %al
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4a40
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x595c
movq %rbx, %rdi
callq 0xb830
nop