// File: /workspace/github_cpp_makefile_star2_O1/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 0x4fad
movq %rdi, %rbx
movl %eax, 0x1c(%rsp)
movb $0x1, 0x40(%rdi)
leaq 0xf(%rsp), %rsi
callq 0x54b4
leaq 0xe(%rsp), %rsi
movq %rbx, %rdi
callq 0x54b4
leaq 0x20(%rsp), %r15
movq %r15, %rdi
callq 0x637c
movq 0x98(%rbx), %rdi
testq %rdi, %rdi
je 0x4ccc
movzbl 0xf(%rsp), %esi
movzbl 0xe(%rsp), %edx
callq 0x7324
movq %rax, %r14
jmp 0x4ccf
xorl %r14d, %r14d
testq %r14, %r14
jne 0x4d1d
movq 0x112ed(%rip), %r14     # 0x15fc8
leaq 0xb97f(%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 0x112bb(%rip), %rdi     # 0x15fc8
callq 0x3040
movq %rax, %rdi
callq 0x31d0
movq %r15, %r14
movq 0x112a4(%rip), %rdi     # 0x15fc8
leaq 0xb94b(%rip), %rsi      # 0x10676
movl $0x9, %edx
callq 0x3320
movzbl 0xf(%rsp), %esi
movq 0x11287(%rip), %rdi     # 0x15fc8
callq 0x3500
movq %rax, %r15
leaq 0xb930(%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
movb %al, 0x11(%r14)
movb 0xe(%rsp), %al
movb %al, 0x12(%r14)
leaq 0x15(%r14), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x54b4
leaq 0x16(%r14), %rsi
movq %rbx, %rdi
movq %rsi, 0x10(%rsp)
callq 0x54b4
leaq 0x17(%r14), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x54b4
leaq 0x18(%r14), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0x54b4
movq 0x111df(%rip), %rdi     # 0x15fc8
leaq 0xb893(%rip), %rsi      # 0x10683
movl $0x6, %edx
callq 0x3320
movzbl (%rbp), %esi
movq 0x111c3(%rip), %rdi     # 0x15fc8
callq 0x3500
movq %rax, %rbp
leaq 0xbb68(%rip), %rsi      # 0x1097c
movl $0x1, %edx
movq %rax, %rdi
callq 0x3320
movq 0x10(%rsp), %rax
movzbl (%rax), %esi
movq %rbp, %rdi
callq 0x3500
movq %rax, %rbp
leaq 0xbb41(%rip), %rsi      # 0x1097c
movl $0x1, %edx
movq %rax, %rdi
callq 0x3320
movzbl (%r13), %esi
movq %rbp, %rdi
callq 0x3500
movq %rax, %r13
leaq 0xbb1d(%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 %r14, %rdi
callq 0x6566
movq %r14, %r15
movq 0x10(%rsp), %rax
cmpb $0x0, (%rax)
je 0x4f88
movl $0x4, %r12d
xorl %r14d, %r14d
movq 0x20(%r15), %rbp
leaq (%r12,%rbp), %r13
addq $-0x4, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x54b4
leaq (%r12,%rbp), %rsi
addq $-0x3, %rsi
movq %rbx, %rdi
callq 0x54b4
leaq (%r12,%rbp), %rsi
addq $-0x2, %rsi
movq %rbx, %rdi
callq 0x54b4
leaq (%r12,%rbp), %rsi
decq %rsi
movq %rbx, %rdi
callq 0x54b4
leaq (%r12,%rbp), %rsi
movq %rbx, %rdi
callq 0x54b4
leaq (%r12,%rbp), %rsi
incq %rsi
movq %rbx, %rdi
callq 0x54b4
leaq (%r12,%rbp), %rsi
addq $0x2, %rsi
movq %rbx, %rdi
callq 0x54fa
movq %r13, %rdi
movq 0x11088(%rip), %rsi     # 0x15fc8
callq 0x5e5e
movq %r13, %rdi
callq 0x5da6
movq 0x4(%rbp,%r12), %rbp
movq %r13, %rdi
callq 0x5de6
movslq %eax, %rdx
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5586
movq %r13, %rdi
callq 0x5dfa
incq %r14
movq 0x10(%rsp), %rax
movzbl (%rax), %eax
addq $0x20, %r12
cmpq %rax, %r14
jb 0x4ec5
movq %r15, %rdi
callq 0x661c
movq 0x11031(%rip), %rsi     # 0x15fc8
movq %r15, %rdi
callq 0x69b2
leaq 0x20(%rsp), %rdi
callq 0x63ae
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 0x4fc6
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x63ae
movq %rbx, %rdi
callq 0xcdb0
nop