// File: /workspace/github_c_makefile_star2_O1/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 0x31f0
leaq 0x48(%rsp), %rdi
movq %rax, (%rdi)
leaq 0x470(%rsp), %r14
movq %r14, %rsi
callq 0x30b0
leaq 0x8f6c(%rip), %rdx      # 0x11c55
leaq 0x50(%rsp), %r15
movl $0x20, %esi
movq %r15, %rdi
movq %r14, %rcx
callq 0x3240
leaq 0x8(%rbx), %rsi
leaq 0x8f61(%rip), %rdi      # 0x11c6a
movq %r15, %rdx
xorl %eax, %eax
callq 0x3160
leaq 0x9183(%rip), %rdi      # 0x11e9d
callq 0x30e0
movq %rbx, %rdi
movl $0x1, %esi
xorl %edx, %edx
callq 0x78a2
testl %eax, %eax
je 0x9107
movzwl 0x554(%rbx), %ebp
movzwl 0x558(%rbx), %eax
movw %ax, 0xe(%rsp)
leaq 0x8f4f(%rip), %r14      # 0x11c9f
movl %ebp, %esi
movq %rbx, %rdi
xorl %edx, %edx
callq 0x78a2
testl %eax, %eax
je 0x9107
movq 0x28(%rbx), %rax
shrq %rax
addq $-0x5, %rax
cmpq $-0x3, %rax
ja 0x8dce
movl $0x1, %eax
movl $0x2, %r15d
movzwl 0x554(%rbx,%rax,2), %eax
testl %eax, %eax
je 0x8db6
movl %eax, %esi
shrl $0x8, %esi
movzbl %al, %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
leal 0x3(%r15), %eax
movq 0x28(%rbx), %rcx
shrq %rcx
addq $-0x3, %rcx
addl $0x4, %r15d
cmpq %rax, %rcx
ja 0x8d80
movzwl 0x554(%rbx), %esi
testl %esi, %esi
jne 0x8d52
movl $0xa, %edi
callq 0x3060
movq %rbx, %rdi
movl %ebp, %esi
xorl %edx, %edx
callq 0x78a2
testl %eax, %eax
je 0x9107
movq 0x28(%rbx), %rax
shrq %rax
addq $-0x5, %rax
cmpq $-0x3, %rax
ja 0x9015
movl $0x1, %edx
movl $0x1, %eax
movzwl 0x554(%rbx,%rax,2), %eax
testl %eax, %eax
je 0x8ffb
movl %edx, %r15d
movzwl 0x558(%rbx,%r15,2), %r14d
movl %eax, %esi
shrl $0x8, %esi
movq %rdx, 0x10(%rsp)
movzbl %al, %edx
leaq 0x8e7d(%rip), %rdi      # 0x11cc7
xorl %eax, %eax
callq 0x3160
leaq 0x90ca(%rip), %rdi      # 0x11f22
callq 0x30e0
movq 0x10(%rsp), %rdx
movzwl 0x556(%rbx,%r15,2), %eax
testw %ax, %ax
je 0x8ffb
leal -0x1(%r14), %ecx
movq %rcx, 0x18(%rsp)
movzwl %ax, %esi
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
callq 0x78a2
testl %eax, %eax
je 0x9107
movq 0x28(%rbx), %rax
shrq %rax
subq 0x18(%rsp), %rax
cmpq $0x2, %rax
jb 0x8fde
movl $0x1, %eax
movl $0x4, %r12d
movzwl 0x70(%rsp,%rax,2), %eax
testw %ax, %ax
jne 0x8ede
leal -0x2(%r12), %ecx
cmpw $0x0, 0x70(%rsp,%rcx,2)
jne 0x8ede
leal -0x1(%r12), %ecx
cmpw $0x0, 0x70(%rsp,%rcx,2)
je 0x8fbb
movzwl %ax, %edi
leaq 0x20(%rsp), %r15
movq %r15, %rsi
callq 0x65fc
leal -0x2(%r12), %eax
movzwl 0x70(%rsp,%rax,2), %edi
leaq 0x23(%rsp), %rsi
callq 0x65fc
movb $0x2e, 0x26(%rsp)
leal -0x1(%r12), %eax
movzwl 0x70(%rsp,%rax,2), %edi
leaq 0x27(%rsp), %rsi
callq 0x65fc
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 0x6787
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 0x8d53(%rip), %rdi      # 0x11cf9
movq %r15, %rsi
xorl %eax, %eax
pushq %rbp
pushq %r13
pushq %r11
pushq %r10
callq 0x3160
addq $0x20, %rsp
leal (%r14,%r12), %eax
addl $-0x3, %eax
leal (%r14,%r12), %ecx
movq 0x28(%rbx), %rdx
shrq %rdx
subq 0x18(%rsp), %rdx
movl %ecx, %r12d
cmpq %rax, %rdx
ja 0x8eb6
movzwl 0x70(%rsp), %eax
testw %ax, %ax
jne 0x8e7d
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 0x8e1a
movzwl 0x554(%rbx), %ebp
testl %ebp, %ebp
jne 0x8de7
leaq 0x8e9e(%rip), %rdi      # 0x11ec9
callq 0x30e0
leaq 0x8d2a(%rip), %r15      # 0x11d61
leaq 0x9a41(%rip), %r12      # 0x12a7f
movl $0xa, %r13d
leaq 0x8d30(%rip), %r14      # 0x11d7b
movzwl 0xe(%rsp), %esi
movq %rbx, %rdi
leaq 0x70(%rsp), %rdx
callq 0x78a2
testl %eax, %eax
je 0x9107
leaq 0x8e87(%rip), %rdi      # 0x11ef3
callq 0x30e0
movzwl 0x70(%rsp), %esi
leaq 0x8cb0(%rip), %rdi      # 0x11d2d
xorl %eax, %eax
callq 0x3160
movzwl 0x72(%rsp), %esi
leaq 0x8ca9(%rip), %rdi      # 0x11d39
xorl %eax, %eax
callq 0x3160
movzwl 0x74(%rsp), %esi
leaq 0x8ca9(%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 0x90ec
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 0x90c3
movq %r12, %rdi
callq 0x30e0
movzwl 0x70(%rsp), %eax
movw %ax, 0xe(%rsp)
testw %ax, %ax
jne 0x904b
addq $0x4a8, %rsp            # imm = 0x4A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq