// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %esi, 0xc(%rsp)
movq %rdi, 0x10(%rsp)
leaq 0xa6(%rsp), %rbx
movl $0xca, %edx
movq %rbx, %rdi
movl $0x2a, %esi
callq 0x10a0
movaps 0x8c6d(%rip), %xmm0     # 0xb140
movaps %xmm0, -0x36(%rbx)
movaps 0x8c72(%rip), %xmm0     # 0xb150
movaps %xmm0, -0x26(%rbx)
movaps 0x8c77(%rip), %xmm0     # 0xb160
movaps %xmm0, -0x16(%rbx)
movq 0x8c7a(%rip), %rax      # 0xb16e
movq %rax, -0x8(%rbx)
xorl %eax, %eax
movq %rax, %r13
movzbl %al, %ebp
xorl %r12d, %r12d
movl $0x1, %ebx
movzbl %r12b, %r14d
movzbl %bl, %ecx
movq 0x10(%rsp), %rdi
movl %ebp, %esi
movl %r14d, %edx
leaq 0x18(%rsp), %r8
xorl %r9d, %r9d
callq 0x20f6
testb %al, %al
je 0x268a
movq 0x50(%rsp), %rsi
movl $0x100, %edx            # imm = 0x100
movl 0xc(%rsp), %edi
callq 0x1060
cmpb $0x0, 0x69(%rsp)
je 0x2553
cmpb $0x0, 0x49(%rsp)
jne 0x25fb
movl $0x10, %edx
movq 0x8a79(%rip), %r15      # 0xafd8
movq %r15, %rdi
leaq 0x5f12(%rip), %rsi      # 0x847b
callq 0x1170
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10b0
movq %rax, %r15
movl $0xa, %edx
movq %rax, %rdi
leaq 0x5f01(%rip), %rsi      # 0x848c
callq 0x1170
movq %r15, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r15
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5eea(%rip), %rsi      # 0x8497
callq 0x1170
movq %r15, %rdi
movq %r12, %rsi
callq 0x10b0
movq %rax, %r15
movl $0xe, %edx
movq %rax, %rdi
leaq 0x604e(%rip), %rsi      # 0x861d
callq 0x1170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x1130
movsbl %al, %esi
movq %r15, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10c0
cmpl $0x100, 0x58(%rsp)      # imm = 0x100
je 0x2745
movl $0x10, %edx
movq 0x89c3(%rip), %r15      # 0xafd8
movq %r15, %rdi
leaq 0x5e5c(%rip), %rsi      # 0x847b
callq 0x1170
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10b0
movq %rax, %r15
movl $0xa, %edx
movq %rax, %rdi
leaq 0x5e4b(%rip), %rsi      # 0x848c
callq 0x1170
movq %r15, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r15
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5e34(%rip), %rsi      # 0x8497
callq 0x1170
movq %r15, %rdi
movq %r12, %rsi
callq 0x10b0
movq %rax, %r15
movl $0x12, %edx
movq %rax, %rdi
leaq 0x5fca(%rip), %rsi      # 0x864f
jmp 0x2719
movl $0x100, %edx            # imm = 0x100
movl 0xc(%rsp), %edi
leaq 0x70(%rsp), %rsi
callq 0x1060
movl $0xf, %edx
movq 0x892f(%rip), %r15      # 0xafd8
movq %r15, %rdi
leaq 0x5dec(%rip), %rsi      # 0x849f
callq 0x1170
movq %r15, %rdi
movq %rbx, %rsi
callq 0x10b0
movq %rax, %r15
movl $0xa, %edx
movq %rax, %rdi
leaq 0x5db7(%rip), %rsi      # 0x848c
callq 0x1170
movq %r15, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r15
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5da0(%rip), %rsi      # 0x8497
callq 0x1170
movq %r15, %rdi
movq %r12, %rsi
callq 0x10b0
movq %rax, %r15
movl $0xb, %edx
movq %rax, %rdi
leaq 0x5ed4(%rip), %rsi      # 0x85ed
callq 0x1170
movq (%r15), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x1130
movsbl %al, %esi
movq %r15, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10c0
incq %rbx
cmpq $0x11, %rbx
jne 0x250c
leaq 0x1(%r12), %rax
movq 0x10(%rsp), %rcx
movzbl 0x145008(%rcx), %ecx
cmpq %rcx, %r12
movq %rax, %r12
jb 0x2503
leaq 0x1(%r13), %rax
movq 0x10(%rsp), %rcx
movzbl 0x145007(%rcx), %ecx
cmpq %rcx, %r13
jb 0x24fa
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq