// File: /workspace/github_cpp_makefile_star2_O1/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 0x70(%rsp), %rbx
movl $0x100, %edx            # imm = 0x100
movq %rbx, %rdi
movl $0x2a, %esi
callq 0x10a0
movaps 0x8c86(%rip), %xmm0     # 0xb140
movaps %xmm0, (%rbx)
movaps 0x8c8c(%rip), %xmm0     # 0xb150
movaps %xmm0, 0x10(%rbx)
movaps 0x8c91(%rip), %xmm0     # 0xb160
movaps %xmm0, 0x20(%rbx)
movq 0x8c94(%rip), %rax      # 0xb16e
movq %rax, 0x2e(%rbx)
xorl %eax, %eax
movq %rax, %rbp
movzbl %al, %r15d
xorl %r13d, %r13d
movl $0x1, %ebx
movzbl %r13b, %r14d
movzbl %bl, %ecx
movq 0x10(%rsp), %rdi
movl %r15d, %esi
movl %r14d, %edx
leaq 0x18(%rsp), %r8
xorl %r9d, %r9d
callq 0x20e8
testb %al, %al
je 0x2673
movq 0x50(%rsp), %rsi
movl $0x100, %edx            # imm = 0x100
movl 0xc(%rsp), %edi
callq 0x1060
cmpb $0x0, 0x69(%rsp)
je 0x253b
cmpb $0x0, 0x49(%rsp)
jne 0x25e4
movl $0x10, %edx
movq 0x8a91(%rip), %r12      # 0xafd8
movq %r12, %rdi
leaq 0x5ece(%rip), %rsi      # 0x841f
callq 0x1170
movq %r12, %rdi
movq %rbx, %rsi
callq 0x10b0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x5ebd(%rip), %rsi      # 0x8430
callq 0x1170
movq %r12, %rdi
movq %rbp, %rsi
callq 0x10b0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5ea6(%rip), %rsi      # 0x843b
callq 0x1170
movq %r12, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r12
movl $0xe, %edx
movq %rax, %rdi
leaq 0x600a(%rip), %rsi      # 0x85c1
callq 0x1170
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x1130
movsbl %al, %esi
movq %r12, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10c0
cmpl $0x100, 0x58(%rsp)      # imm = 0x100
je 0x272f
movl $0x10, %edx
movq 0x89da(%rip), %r12      # 0xafd8
movq %r12, %rdi
leaq 0x5e17(%rip), %rsi      # 0x841f
callq 0x1170
movq %r12, %rdi
movq %rbx, %rsi
callq 0x10b0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x5e06(%rip), %rsi      # 0x8430
callq 0x1170
movq %r12, %rdi
movq %rbp, %rsi
callq 0x10b0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5def(%rip), %rsi      # 0x843b
callq 0x1170
movq %r12, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r12
movl $0x12, %edx
movq %rax, %rdi
leaq 0x5f85(%rip), %rsi      # 0x85f3
jmp 0x2702
movl $0x100, %edx            # imm = 0x100
movl 0xc(%rsp), %edi
leaq 0x70(%rsp), %rsi
callq 0x1060
movl $0xf, %edx
movq 0x8946(%rip), %r12      # 0xafd8
movq %r12, %rdi
leaq 0x5da7(%rip), %rsi      # 0x8443
callq 0x1170
movq %r12, %rdi
movq %rbx, %rsi
callq 0x10b0
movq %rax, %r12
movl $0xa, %edx
movq %rax, %rdi
leaq 0x5d72(%rip), %rsi      # 0x8430
callq 0x1170
movq %r12, %rdi
movq %rbp, %rsi
callq 0x10b0
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x5d5b(%rip), %rsi      # 0x843b
callq 0x1170
movq %r12, %rdi
movq %r13, %rsi
callq 0x10b0
movq %rax, %r12
movl $0xb, %edx
movq %rax, %rdi
leaq 0x5e8f(%rip), %rsi      # 0x8591
callq 0x1170
movq (%r12), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x1130
movsbl %al, %esi
movq %r12, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10c0
incq %rbx
cmpq $0x11, %rbx
jne 0x24f3
leaq 0x1(%r13), %rax
movq 0x10(%rsp), %rcx
movzbl 0x145008(%rcx), %ecx
cmpq %rcx, %r13
movq %rax, %r13
jb 0x24ea
leaq 0x1(%rbp), %rax
movq 0x10(%rsp), %rcx
movzbl 0x145007(%rcx), %ecx
cmpq %rcx, %rbp
jb 0x24e0
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop