// File: pelrun[P]aft/CDSKFile.cpp
// Function: CDSKTrack::Write(std::ostream&)
bool CDSKTrack::Write(std::ostream &str)
{
	unsigned int trackPos = str.tellp();
	
	str.write((char*)&Header, 13);
	str.write((char*)&Unused, 3);
	str.write((char*)&TrackNumber, 1);
	str.write((char*)&SideNumber, 1);
	str.write((char*)&DataRate, 1);
	str.write((char*)&RecordingMode, 1);
	str.write((char*)&SectorSize, 1);
	str.write((char*)&NbSector, 1);
	str.write((char*)&GAP3Size, 1);
	str.write((char*)&FillByte, 1);

	int s;
	for (s=0 ; s<NbSector ; s++)
	{
		Sectors[s].WriteHeader(str);
	}

	int nbBlank = (trackPos+0x100) - str.tellp();
	if (nbBlank != 0)
	{
		unsigned char *buff = new unsigned char[nbBlank];
		memset(buff, 0, nbBlank);
		str.write((char*)buff, nbBlank);
		delete[] buff;
	}

	for (s=0 ; s<NbSector ; s++)
	{
		Sectors[s].WriteData(str);
	}

	return true;
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x58(%rsp), %rdi
callq 0x4290
movq %rax, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
leaq 0x40(%rsp), %rdi
callq 0x72d0
movq 0x18(%rsp), %rsi
movl %eax, 0x54(%rsp)
movq 0x58(%rsp), %rdi
movl $0xd, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0xe, %rsi
movl $0x3, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x11, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x12, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x13, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x14, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x15, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x16, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x17, %rsi
movl $0x1, %edx
callq 0x44a0
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %rdi
addq $0x18, %rsi
movl $0x1, %edx
callq 0x44a0
movl $0x0, 0x3c(%rsp)
movq 0x18(%rsp), %rcx
movl 0x3c(%rsp), %eax
movzbl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x92fb
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rdi
movslq 0x3c(%rsp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x82a0
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x92be
movl 0x54(%rsp), %eax
addl $0x100, %eax            # imm = 0x100
movl %eax, %eax
movq %rax, 0x10(%rsp)
movq 0x58(%rsp), %rdi
callq 0x4290
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
leaq 0x28(%rsp), %rdi
callq 0x72d0
movq %rax, %rcx
movq 0x10(%rsp), %rax
subq %rcx, %rax
movl %eax, 0x38(%rsp)
cmpl $0x0, 0x38(%rsp)
je 0x938f
movslq 0x38(%rsp), %rdi
callq 0x4030
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
movslq 0x38(%rsp), %rdx
xorl %esi, %esi
callq 0x41a0
movq 0x58(%rsp), %rdi
movq 0x20(%rsp), %rsi
movslq 0x38(%rsp), %rdx
callq 0x44a0
movq 0x20(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x938d
movq 0x8(%rsp), %rdi
callq 0x4490
jmp 0x938f
movl $0x0, 0x3c(%rsp)
movq 0x18(%rsp), %rcx
movl 0x3c(%rsp), %eax
movzbl 0x16(%rcx), %ecx
cmpl %ecx, %eax
jge 0x93d4
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rdi
movslq 0x3c(%rsp), %rax
shlq $0x5, %rax
addq %rax, %rdi
movq 0x58(%rsp), %rsi
callq 0x8500
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x9397
movb $0x1, %al
andb $0x1, %al
addq $0x68, %rsp
retq
nopl (%rax)