// File: atsidaev[P]trx2x/DiskImage.cpp
// Function: TDiskImage::writeTRD(int)
void TDiskImage::writeTRD(int hfile)
{
   VGFIND_SECTOR vgfs;

// prepare nullbuf...
   unsigned char nullbuf[256];
   for(int i=0; i < 256; i++) nullbuf[i] = '*';
   memcpy(nullbuf, errsect, sizeof(errsect));

   for(unsigned int trk=0; trk <= unsigned(MaxTrack); trk++)
      for(unsigned int side=0; side <= unsigned(MaxSide); side++)
         for(unsigned int sec=0; sec < 16; sec++)
         {
            if(FindSector(trk, side, sec+1, &vgfs))
            {
               write(hfile, vgfs.SectorPointer, 256);
               if((!vgfs.CRCOK)||(!vgfs.vgfa.CRCOK)) cout << "Warning: sector "<<(sec+1)<<" on track "<<trk<<", side "<<side<<" with BAD CRC!" << endl;
               if(vgfs.SectorLength != 256) cout << "Warning: sector "<<(sec+1)<<" on track "<<trk<<", side "<<side<<" is non 256 bytes!" << endl;
            }
            else 
            {
               write(hfile, nullbuf, 256);
               cout << "DANGER! Sector "<<(sec+1)<<" on track "<<trk<<", side "<<side<<" not found!" << endl;
            }
         }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x188(%rbp)
movl $0x0, -0x174(%rbp)
cmpl $0x100, -0x174(%rbp)    # imm = 0x100
jge 0x2cd3
movslq -0x174(%rbp), %rax
movb $0x2a, -0x170(%rbp,%rax)
movl -0x174(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x174(%rbp)
jmp 0x2ca7
leaq -0x170(%rbp), %rdi
leaq 0xe44f(%rip), %rsi      # 0x11130
movl $0x36, %edx
callq 0x10c0
movl $0x0, -0x178(%rbp)
movq -0x188(%rbp), %rcx
movl -0x178(%rbp), %eax
movzbl 0x145007(%rcx), %ecx
cmpl %ecx, %eax
ja 0x2f81
movl $0x0, -0x17c(%rbp)
movq -0x188(%rbp), %rcx
movl -0x17c(%rbp), %eax
movzbl 0x145008(%rcx), %ecx
cmpl %ecx, %eax
ja 0x2f6b
movl $0x0, -0x180(%rbp)
cmpl $0x10, -0x180(%rbp)
jae 0x2f55
movq -0x188(%rbp), %rdi
movl -0x178(%rbp), %eax
movb %al, %dl
movl -0x17c(%rbp), %eax
movb %al, %cl
movl -0x180(%rbp), %eax
addl $0x1, %eax
leaq -0x68(%rbp), %r8
xorl %r9d, %r9d
movzbl %dl, %esi
movzbl %cl, %edx
movzbl %al, %ecx
callq 0x25d0
testb $0x1, %al
jne 0x2d8c
jmp 0x2eaf
movl -0xc(%rbp), %edi
movq -0x30(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x1050
cmpb $0x0, -0x17(%rbp)
je 0x2da9
cmpb $0x0, -0x37(%rbp)
jne 0x2e25
movq 0xe228(%rip), %rdi      # 0x10fd8
leaq 0xb660(%rip), %rsi      # 0xe417
callq 0x1110
movq %rax, %rdi
movl -0x180(%rbp), %esi
addl $0x1, %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb651(%rip), %rsi      # 0xe428
callq 0x1110
movq %rax, %rdi
movl -0x178(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb63f(%rip), %rsi      # 0xe433
callq 0x1110
movq %rax, %rdi
movl -0x17c(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb7a8(%rip), %rsi      # 0xe5b9
callq 0x1110
movq %rax, %rdi
movq 0xe1a8(%rip), %rsi      # 0x10fc8
callq 0x1140
cmpl $0x100, -0x28(%rbp)     # imm = 0x100
je 0x2eaa
movq 0xe1a3(%rip), %rdi      # 0x10fd8
leaq 0xb5db(%rip), %rsi      # 0xe417
callq 0x1110
movq %rax, %rdi
movl -0x180(%rbp), %esi
addl $0x1, %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb5cc(%rip), %rsi      # 0xe428
callq 0x1110
movq %rax, %rdi
movl -0x178(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb5ba(%rip), %rsi      # 0xe433
callq 0x1110
movq %rax, %rdi
movl -0x17c(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb755(%rip), %rsi      # 0xe5eb
callq 0x1110
movq %rax, %rdi
movq 0xe123(%rip), %rsi      # 0x10fc8
callq 0x1140
jmp 0x2f3f
movl -0xc(%rbp), %edi
leaq -0x170(%rbp), %rsi
movl $0x100, %edx            # imm = 0x100
callq 0x1050
movq 0xe10e(%rip), %rdi      # 0x10fd8
leaq 0xb56a(%rip), %rsi      # 0xe43b
callq 0x1110
movq %rax, %rdi
movl -0x180(%rbp), %esi
addl $0x1, %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb537(%rip), %rsi      # 0xe428
callq 0x1110
movq %rax, %rdi
movl -0x178(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb525(%rip), %rsi      # 0xe433
callq 0x1110
movq %rax, %rdi
movl -0x17c(%rbp), %esi
callq 0x1170
movq %rax, %rdi
leaq 0xb65e(%rip), %rsi      # 0xe589
callq 0x1110
movq %rax, %rdi
movq 0xe08e(%rip), %rsi      # 0x10fc8
callq 0x1140
jmp 0x2f41
movl -0x180(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x180(%rbp)
jmp 0x2d41
jmp 0x2f57
movl -0x17c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x17c(%rbp)
jmp 0x2d1b
jmp 0x2f6d
movl -0x178(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x178(%rbp)
jmp 0x2cf5
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw (%rax,%rax)