// File: /workspace/github_c_makefile_star2_O2/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 0x96b6(%rip), %rdx      # 0x10c55
leaq 0x50(%rsp), %r15
pushq $0x20
popq %rsi
movq %r15, %rdi
movq %r14, %rcx
callq 0x3250
leaq 0x8(%rbx), %rsi
leaq 0x96ad(%rip), %rdi      # 0x10c6a
movq %r15, %rdx
xorl %eax, %eax
callq 0x3160
leaq 0x98cf(%rip), %rdi      # 0x10e9d
callq 0x30e0
pushq $0x1
popq %rsi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x5ffa
testl %eax, %eax
je 0x7957
movzwl 0x554(%rbx), %r12d
movzwl 0x558(%rbx), %eax
movw %ax, 0xe(%rsp)
pushq $0x3
popq %rbp
leaq 0x9699(%rip), %r14      # 0x10c9f
movl %r12d, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x5ffa
testl %eax, %eax
je 0x7957
movl %ebp, %r15d
leal -0x2(%r15), %eax
movq 0x28(%rbx), %rcx
shrq %rcx
addq $-0x3, %rcx
cmpq %rax, %rcx
jbe 0x766e
movzwl 0x554(%rbx,%rax,2), %eax
testl %eax, %eax
je 0x7668
movl %eax, %esi
shrl $0x8, %esi
movzbl %al, %edx
leal -0x1(%r15), %eax
movzwl 0x554(%rbx,%rax,2), %ecx
movl %r15d, %eax
movzwl 0x554(%rbx,%rax,2), %r8d
movq %r14, %rdi
xorl %eax, %eax
callq 0x3160
addl $0x4, %r15d
jmp 0x761e
movzwl 0x554(%rbx), %esi
testl %esi, %esi
jne 0x7609
pushq $0xa
popq %rdi
callq 0x3060
movq %rbx, %rdi
movl %r12d, %esi
xorl %edx, %edx
callq 0x5ffa
testl %eax, %eax
je 0x7957
pushq $0x1
popq %rax
movl %eax, %r14d
movl %r14d, %r14d
movq 0x28(%rbx), %rax
shrq %rax
addq $-0x3, %rax
cmpq %r14, %rax
jbe 0x786b
movzwl 0x554(%rbx,%r14,2), %eax
testl %eax, %eax
je 0x7862
movzwl 0x558(%rbx,%r14,2), %r12d
movl %eax, %esi
shrl $0x8, %esi
movzbl %al, %edx
leaq 0x95eb(%rip), %rdi      # 0x10cc7
xorl %eax, %eax
callq 0x3160
leaq 0x9838(%rip), %rdi      # 0x10f22
callq 0x30e0
movzwl 0x556(%rbx,%r14,2), %eax
testw %ax, %ax
je 0x7862
movq %r14, 0x10(%rsp)
leal -0x1(%r12), %ecx
movq %rcx, 0x18(%rsp)
movzwl %ax, %esi
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
callq 0x5ffa
testl %eax, %eax
je 0x7957
pushq $0x9
popq %rax
movl %eax, %r13d
leal -0x8(%r13), %eax
movq 0x28(%rbx), %rcx
shrq %rcx
subq 0x18(%rsp), %rcx
cmpq %rax, %rcx
jbe 0x7847
movzwl 0x70(%rsp,%rax,2), %eax
leal -0x7(%r13), %ebp
testw %ax, %ax
jne 0x776d
cmpw $0x0, 0x70(%rsp,%rbp,2)
jne 0x776d
leal -0x6(%r13), %ecx
cmpw $0x0, 0x70(%rsp,%rcx,2)
je 0x783f
movzwl %ax, %edi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x5068
movzwl 0x70(%rsp,%rbp,2), %edi
leaq 0x23(%rsp), %rsi
callq 0x5068
movb $0x2e, 0x26(%rsp)
leal -0x6(%r13), %eax
movzwl 0x70(%rsp,%rax,2), %edi
leaq 0x27(%rsp), %rsi
callq 0x5068
movw $0x2020, 0x2a(%rsp)     # imm = 0x2020
leal -0x5(%r13), %ebp
movzwl 0x70(%rsp,%rbp,2), %edi
andl $0x7fff, %edi           # imm = 0x7FFF
leaq 0x2c(%rsp), %rsi
callq 0x51da
movb $0x0, 0x39(%rsp)
xorl %eax, %eax
cmpw $0x0, 0x70(%rsp,%rbp,2)
setns %al
leal (%rax,%rax,8), %edx
addl $0x43, %edx
movl %r13d, %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 -0x3(%r13), %esi
movzwl 0x70(%rsp,%rsi,2), %r9d
leal -0x2(%r13), %esi
movzwl 0x70(%rsp,%rsi,2), %r10d
leal -0x1(%r13), %esi
movzwl 0x70(%rsp,%rsi,2), %r11d
movzbl %al, %ebp
leal -0x4(%r13), %eax
movzwl 0x70(%rsp,%rax,2), %r14d
leaq 0x94cf(%rip), %rdi      # 0x10cf9
movq %r15, %rsi
xorl %eax, %eax
pushq %r14
pushq %rbp
pushq %r11
pushq %r10
callq 0x3160
addq $0x20, %rsp
addl %r12d, %r13d
jmp 0x772e
movzwl 0x70(%rsp), %eax
testw %ax, %ax
jne 0x7710
pushq $0xa
popq %rdi
callq 0x3060
movq 0x10(%rsp), %r14
addl $0x4, %r14d
jmp 0x769c
movzwl 0x554(%rbx), %r12d
testl %r12d, %r12d
jne 0x7681
leaq 0x9646(%rip), %rdi      # 0x10ec9
callq 0x30e0
leaq 0x94d2(%rip), %r15      # 0x10d61
pushq $0x20
popq %r13
leaq 0x94e1(%rip), %r12      # 0x10d7b
leaq 0xa1de(%rip), %r14      # 0x11a7f
movzwl 0xe(%rsp), %esi
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
callq 0x5ffa
testl %eax, %eax
je 0x7957
leaq 0x9631(%rip), %rdi      # 0x10ef3
callq 0x30e0
movzwl 0x70(%rsp), %esi
leaq 0x945a(%rip), %rdi      # 0x10d2d
xorl %eax, %eax
callq 0x3160
movzwl 0x72(%rsp), %esi
leaq 0x9453(%rip), %rdi      # 0x10d39
xorl %eax, %eax
callq 0x3160
movzwl 0x74(%rsp), %esi
leaq 0x9453(%rip), %rdi      # 0x10d4c
xorl %eax, %eax
callq 0x3160
movzwl 0x76(%rsp), %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x3160
xorl %ebp, %ebp
movzwl 0x74(%rsp), %eax
cmpq %rax, %rbp
jae 0x793c
movzwl 0x78(%rsp,%rbp,2), %esi
incq %rbp
testb $0x7, %bpl
movl %r13d, %edx
pushq $0xa
popq %rax
cmovel %eax, %edx
movq %r12, %rdi
xorl %eax, %eax
callq 0x3160
jmp 0x7911
movq %r14, %rdi
callq 0x30e0
movzwl 0x70(%rsp), %eax
movw %ax, 0xe(%rsp)
testw %ax, %ax
jne 0x78a1
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq