// File: /workspace/github_c_makefile_star2_O3/simh[P]simtools/converters/fsio/dos11.c
// Function: dos11Info
static void dos11Info(
  struct mountedFS *mount,
  uint8_t UNUSED(unit),
  uint8_t UNUSED(present)
)
{
  struct DOS11data *data = &mount->dos11data;
  struct tm tm;
  char datetime[32], temp[32];
  time_t now = time(NULL);
  unsigned int mfd2blk, mfdblk, ufdblk, mapblk, i, j;
  uint16_t buf[512];

  localtime_r(&now, &tm);
  strftime(datetime, sizeof(datetime), "%d-%b-%C at %I:%M:%S", &tm);

  printf("* * * * * * Listing of MFD for %s * * * * * * on %s\n",
         mount->name, datetime);
  printf("      UIC  First UFD Block  UFD Entry Size\n\n");

  if (dos11ReadBlock(mount, MFD1_BLOCK, NULL) == 0)
    return;

  /*
   * Get some useful block addresses
   */
  mfd2blk = le16toh(data->buf[MFD1_MFD2BLOCK]);
  mapblk = le16toh(data->buf[MFD1_BMSTART]);

  /*
   * Display the MFD entries
   */
  mfdblk = mfd2blk;
  do {
    if (dos11ReadBlock(mount, mfdblk, NULL) == 0)
      return;

    for (i = MFD2_HEADER; i < EODIR(mount, MFD2_SIZE); i += MFD2_SIZE)
      if (le16toh(data->buf[i + MFD2_UFDUIC]) != 0) {
        printf("[%3o,%3o]            %5o          %5d.\n",
               (le16toh(data->buf[i + MFD2_UFDUIC]) >> 8) & 0377,
               le16toh(data->buf[i + MFD2_UFDUIC]) & 0377,
               le16toh(data->buf[i + MFD2_UFDSTART]),
               le16toh(data->buf[i + MFD2_UFDSIZE]));
      }
    mfdblk = le16toh(data->buf[MFD2_LINK]);
  } while (mfdblk != 0);

  printf("\n");

  /*
   * Display the individual UFD entries
   */
  mfdblk = mfd2blk;
  do {
    if (dos11ReadBlock(mount, mfdblk, NULL) == 0)
      return;

    for (i = MFD2_HEADER; i < EODIR(mount, MFD2_SIZE); i += MFD2_SIZE)
      if (le16toh(data->buf[i + MFD2_UFDUIC]) != 0) {
        unsigned int entrysz = le16toh(data->buf[i + MFD2_UFDSIZE]);

        printf("* * * Listing of [%3o,%3o] User Directory * * *\n\n",
               (le16toh(data->buf[i + MFD2_UFDUIC]) >> 8) & 0377,
               le16toh(data->buf[i + MFD2_UFDUIC]) & 0377);
        printf("  File Ext         Date  Type  Usage  Lock   Start  Length      End  Prot    EBP\n\n");

        if ((ufdblk = le16toh(data->buf[i + MFD2_UFDSTART])) != 0) {
          do {
            if (dos11ReadBlock(mount, ufdblk, buf) == 0)
              return;

            for (j = UFD_HEADER; j < EODIR(mount, entrysz); j += entrysz) {
              /*
               * Skip over deleted files
               */
              if ((le16toh(buf[j + UFD_FILENAME]) == 0) &&
                  (le16toh(buf[j + UFD_FILENAME + 1]) == 0) &&
                  (le16toh(buf[j + UFD_EXTENSION]) == 0))
                continue;

              r50Asc(le16toh(buf[j + UFD_FILENAME]), &temp[0]);
              r50Asc(le16toh(buf[j + UFD_FILENAME + 1]), &temp[3]);
              temp[6] = '.';
              r50Asc(le16toh(buf[j + UFD_EXTENSION]), &temp[7]);
              temp[10] = ' ';
              temp[11] = ' ';
              dos11Date(le16toh(buf[j + UFD_CREATION]) & UFD_DATE, &temp[12]);
              temp[25] = '\0';

              printf("%s     %c    %3o     %c  %6o  %5u.   %6o   %3o %6o\n",
                     temp,
                     (le16toh(buf[j + UFD_CREATION]) & UFD_TYPE) ? 'C' : 'L',
                     (le16toh(buf[j + UFD_LUP]) & UFD_USAGE) >> 8,
                     (le16toh(buf[j + UFD_LUP]) & UFD_LOCK) ? '1' : '0',
                     le16toh(buf[j + UFD_FILESTART]),
                     le16toh(buf[j + UFD_FILELENGTH]),
                     le16toh(buf[j + UFD_LASTBLOCKWRITTEN]),
                     le16toh(buf[j + UFD_LUP]) & UFD_PROT,
                     le16toh(buf[j + UFD_NEXTFREEBYTE]));
            }
            ufdblk = le16toh(buf[UFD_LINK]);
          } while (ufdblk != 0);
          printf("\n");
        }
      }
    mfdblk = le16toh(data->buf[MFD2_LINK]);
  } while (mfdblk != 0);

  /*
   * Display bitmap information
   */
  printf("* * * * * * Map Verification * * * * * *\n\n");
  do {
    if (dos11ReadBlock(mount, mapblk, buf) == 0)
      return;

    printf("* * * * * * Map Header Information * * * * * *\n");
    printf("Link = %6o\n", le16toh(buf[MAP_LINK]));
    printf("Map Number = %2u.\n", le16toh(buf[MAP_MAP]));
    printf("Words In Map = %3u.\n", le16toh(buf[MAP_WORDS]));
    printf("Link To First Map = %6o\n\n", le16toh(buf[MAP_FIRST]));

    for (i = 0; i < le16toh(buf[MAP_WORDS]); i++)
      printf(" %6o%c",
             le16toh(buf[MAP_BMSTART + i]),
             ((i + 1) % 8) == 0 ? '\n' : ' ');
    printf("\n\n");

    mapblk = le16toh(buf[MAP_LINK]);
  } while (mapblk != 0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4a8, %rsp            # imm = 0x4A8
movq %rdi, %rbx
xorl %edi, %edi
callq 0x3200
leaq 0x48(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x470(%rsp), %r14
movq %r14, %rsi
callq 0x30b0
leaq 0x9231(%rip), %rdx      # 0x11c55
leaq 0x50(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
movq %r14, %rcx
callq 0x3250
leaq 0x8(%rbx), %rsi
leaq 0x9226(%rip), %rdi      # 0x11c6a
movq %r15, %rdx
xorl %eax, %eax
callq 0x3160
leaq 0x9448(%rip), %rdi      # 0x11e9d
callq 0x30e0
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x7621
testl %eax, %eax
je 0x8e4b
movzwl 0x554(%rbx), %ebp
movzwl 0x558(%rbx), %eax
movw %ax, 0xe(%rsp)
leaq 0x9214(%rip), %r14      # 0x11c9f
movl %ebp, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x7621
testl %eax, %eax
je 0x8e4b
movq 0x28(%rbx), %rax
movq %rax, %rcx
shrq %rcx
addq $-0x5, %rcx
cmpq $-0x3, %rcx
ja 0x8b0f
movl $0x1, %ecx
movl $0x2, %r15d
movzwl 0x554(%rbx,%rcx,2), %ecx
testl %ecx, %ecx
je 0x8af8
movl %ecx, %esi
shrl $0x8, %esi
movzbl %cl, %edx
movl %r15d, %eax
movzwl 0x554(%rbx,%rax,2), %ecx
leal 0x1(%r15), %eax
movzwl 0x554(%rbx,%rax,2), %r8d
movq %r14, %rdi
xorl %eax, %eax
callq 0x3160
movq 0x28(%rbx), %rax
leal 0x3(%r15), %ecx
movq %rax, %rdx
shrq %rdx
addq $-0x3, %rdx
addl $0x4, %r15d
cmpq %rcx, %rdx
ja 0x8abe
movzwl 0x554(%rbx), %esi
testl %esi, %esi
jne 0x8a8d
movl $0xa, %edi
callq 0x3060
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x7621
testl %eax, %eax
je 0x8e4b
movq 0x28(%rbx), %rax
shrq %rax
addq $-0x5, %rax
cmpq $-0x3, %rax
ja 0x8d59
movl $0x1, %edx
movl $0x1, %eax
movzwl 0x554(%rbx,%rax,2), %eax
testl %eax, %eax
je 0x8d3f
movl %edx, %r15d
movzwl 0x558(%rbx,%r15,2), %r14d
movl %eax, %esi
shrl $0x8, %esi
movq %rdx, 0x10(%rsp)
movzbl %al, %edx
leaq 0x913c(%rip), %rdi      # 0x11cc7
xorl %eax, %eax
callq 0x3160
leaq 0x9389(%rip), %rdi      # 0x11f22
callq 0x30e0
movq 0x10(%rsp), %rdx
movzwl 0x556(%rbx,%r15,2), %eax
testw %ax, %ax
je 0x8d3f
leal -0x1(%r14), %ecx
movq %rcx, 0x18(%rsp)
movzwl %ax, %esi
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
callq 0x7621
testl %eax, %eax
je 0x8e4b
movq 0x28(%rbx), %rax
movq %rax, %rcx
shrq %rcx
subq 0x18(%rsp), %rcx
cmpq $0x2, %rcx
jb 0x8d22
movl $0x1, %ecx
movl $0x4, %r12d
movzwl 0x70(%rsp,%rcx,2), %ecx
leal -0x2(%r12), %r13d
testw %cx, %cx
jne 0x8c23
cmpw $0x0, 0x70(%rsp,%r13,2)
jne 0x8c23
leal -0x1(%r12), %edx
cmpw $0x0, 0x70(%rsp,%rdx,2)
je 0x8d00
movzwl %cx, %edi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x658c
movzwl 0x70(%rsp,%r13,2), %edi
leaq 0x23(%rsp), %rsi
callq 0x658c
movb $0x2e, 0x26(%rsp)
leal -0x1(%r12), %eax
movzwl 0x70(%rsp,%rax,2), %edi
leaq 0x27(%rsp), %rsi
callq 0x658c
movw $0x2020, 0x2a(%rsp)     # imm = 0x2020
movl %r12d, %r13d
movzwl 0x70(%rsp,%r13,2), %edi
andl $0x7fff, %edi           # imm = 0x7FFF
leaq 0x2c(%rsp), %rsi
callq 0x6729
movb $0x0, 0x39(%rsp)
xorl %eax, %eax
cmpw $0x0, 0x70(%rsp,%r13,2)
setns %al
leal 0x43(%rax,%rax,8), %edx
leal 0x5(%r12), %eax
movzwl 0x70(%rsp,%rax,2), %eax
movl %eax, %ecx
shrl $0x8, %ecx
andl $0x7f, %ecx
xorl %r8d, %r8d
testw %ax, %ax
setns %r8b
xorl $0x31, %r8d
leal 0x2(%r12), %esi
movzwl 0x70(%rsp,%rsi,2), %r9d
leal 0x3(%r12), %esi
movzwl 0x70(%rsp,%rsi,2), %r10d
leal 0x4(%r12), %esi
movzwl 0x70(%rsp,%rsi,2), %r11d
movzbl %al, %r13d
leal 0x1(%r12), %eax
movzwl 0x70(%rsp,%rax,2), %ebp
leaq 0x9012(%rip), %rdi      # 0x11cf9
movq %r15, %rsi
xorl %eax, %eax
pushq %rbp
pushq %r13
pushq %r11
pushq %r10
callq 0x3160
addq $0x20, %rsp
movq 0x28(%rbx), %rax
leal (%r14,%r12), %ecx
addl $-0x3, %ecx
leal (%r14,%r12), %edx
movq %rax, %rsi
shrq %rsi
subq 0x18(%rsp), %rsi
movl %edx, %r12d
cmpq %rcx, %rsi
ja 0x8bfa
movzwl 0x70(%rsp), %eax
testw %ax, %ax
jne 0x8bbe
movl $0xa, %edi
callq 0x3060
movq 0x10(%rsp), %rdx
addl $0x4, %edx
movq 0x28(%rbx), %rcx
shrq %rcx
addq $-0x3, %rcx
movq %rdx, %rax
cmpq %rdx, %rcx
ja 0x8b5b
movzwl 0x554(%rbx), %ebp
testl %ebp, %ebp
jne 0x8b28
leaq 0x915a(%rip), %rdi      # 0x11ec9
callq 0x30e0
leaq 0x8fe6(%rip), %r15      # 0x11d61
leaq 0x9d1d(%rip), %r12      # 0x12a9f
movl $0xa, %r13d
leaq 0x8fec(%rip), %r14      # 0x11d7b
movzwl 0xe(%rsp), %esi
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
callq 0x7621
testl %eax, %eax
je 0x8e4b
leaq 0x9143(%rip), %rdi      # 0x11ef3
callq 0x30e0
movzwl 0x70(%rsp), %esi
leaq 0x8f6c(%rip), %rdi      # 0x11d2d
xorl %eax, %eax
callq 0x3160
movzwl 0x72(%rsp), %esi
leaq 0x8f65(%rip), %rdi      # 0x11d39
xorl %eax, %eax
callq 0x3160
movzwl 0x74(%rsp), %esi
leaq 0x8f65(%rip), %rdi      # 0x11d4c
xorl %eax, %eax
callq 0x3160
movzwl 0x76(%rsp), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x3160
cmpw $0x0, 0x74(%rsp)
je 0x8e30
xorl %ebp, %ebp
movzwl 0x78(%rsp,%rbp,2), %esi
incq %rbp
testb $0x7, %bpl
movl $0x20, %edx
cmovel %r13d, %edx
movq %r14, %rdi
xorl %eax, %eax
callq 0x3160
movzwl 0x74(%rsp), %eax
cmpq %rax, %rbp
jb 0x8e07
movq %r12, %rdi
callq 0x30e0
movzwl 0x70(%rsp), %eax
movw %ax, 0xe(%rsp)
testw %ax, %ax
jne 0x8d8f
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq