// File: /workspace/github_cpp_makefile_star2_O3/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 0x4fcf
movq %rdi, %rbx
movl %eax, 0x1c(%rsp)
movb $0x1, 0x40(%rdi)
leaq 0xf(%rsp), %rsi
callq 0x54d2
leaq 0xe(%rsp), %rsi
movq %rbx, %rdi
callq 0x54d2
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x635a
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x4ce8
movzbl 0xf(%rsp), %esi
movzbl 0xe(%rsp), %edx
callq 0x7328
movq %rax, 0x10(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x4d33
movq 0x112d9(%rip), %r14     # 0x15fc8
leaq 0xb96b(%rip), %rsi      # 0x10661
movl $0x14, %edx
movq %r14, %rdi
callq 0x3320
movq (%r14), %rax
addq -0x18(%rax), %r14
movq %r14, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq 0x112a7(%rip), %rdi     # 0x15fc8
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq %r15, 0x10(%rsp)
movq 0x1128e(%rip), %rdi     # 0x15fc8
leaq 0xb935(%rip), %rsi      # 0x10676
movl $0x9, %edx
callq 0x3320
movzbl 0xf(%rsp), %esi
movq 0x11271(%rip), %rdi     # 0x15fc8
callq 0x3500
movq %rax, %r15
leaq 0xb91a(%rip), %rsi      # 0x10680
movl $0x2, %edx
movq %rax, %rdi
callq 0x3320
movzbl 0xe(%rsp), %esi
movq %r15, %rdi
callq 0x3500
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r15, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
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 0x54d2
movq 0x10(%rsp), %rax
leaq 0x16(%rax), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x54d2
movq 0x10(%rsp), %rax
leaq 0x17(%rax), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x54d2
movq 0x10(%rsp), %rax
leaq 0x18(%rax), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x54d2
movq 0x111b9(%rip), %rdi     # 0x15fc8
leaq 0xb86d(%rip), %rsi      # 0x10683
movl $0x6, %edx
callq 0x3320
movzbl (%rbp), %esi
movq 0x1119d(%rip), %rdi     # 0x15fc8
callq 0x3500
movq %rax, %rbp
leaq 0xbb42(%rip), %rsi      # 0x1097c
movl $0x1, %edx
movq %rax, %rdi
callq 0x3320
movzbl (%r15), %esi
movq %rbp, %rdi
callq 0x3500
movq %rax, %rbp
leaq 0xbb1f(%rip), %rsi      # 0x1097c
movl $0x1, %edx
movq %rax, %rdi
callq 0x3320
movzbl (%r13), %esi
movq %rbp, %rdi
callq 0x3500
movq %rax, %r13
leaq 0xbafb(%rip), %rsi      # 0x1097c
movl $0x1, %edx
movq %rax, %rdi
callq 0x3320
movzbl (%r12), %esi
movq %r13, %rdi
callq 0x3500
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x3290
movsbl %al, %esi
movq %r12, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq 0x10(%rsp), %rdi
callq 0x6544
cmpb $0x0, (%r15)
je 0x4fa6
movl $0x4, %r12d
xorl %r14d, %r14d
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rbp
leaq (%r12,%rbp), %r13
addq $-0x4, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x54d2
leaq (%r12,%rbp), %rsi
addq $-0x3, %rsi
movq %rbx, %rdi
callq 0x54d2
leaq (%r12,%rbp), %rsi
addq $-0x2, %rsi
movq %rbx, %rdi
callq 0x54d2
leaq (%r12,%rbp), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x54d2
leaq (%r12,%rbp), %rsi
movq %rbx, %rdi
callq 0x54d2
leaq (%r12,%rbp), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x54d2
leaq (%r12,%rbp), %rsi
addq $0x2, %rsi
movq %rbx, %rdi
callq 0x5518
movq %r13, %rdi
movq 0x11066(%rip), %rsi     # 0x15fc8
callq 0x5e5a
movq %r13, %rdi
callq 0x5da2
movq 0x4(%rbp,%r12), %rbp
movq %r13, %rdi
callq 0x5de2
movslq %eax, %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x55a4
movq %r13, %rdi
callq 0x5df6
incq %r14
movzbl (%r15), %eax
addq $0x20, %r12
cmpq %rax, %r14
jb 0x4ee2
movq 0x10(%rsp), %rdi
callq 0x65fa
movq 0x11011(%rip), %rsi     # 0x15fc8
movq 0x10(%rsp), %rdi
callq 0x6996
leaq 0x20(%rsp), %rdi
callq 0x638c
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 0x4fe8
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x638c
movq %rbx, %rdi
callq 0xce30
nop