// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/converters/fsio/os8.c
// Function: os8Dir
static void os8Dir(
  struct mountedFS *mount,
  uint8_t unit,
  char *fname
)
{
  struct OS8data *data = &mount->os8data;
  struct os8FileSpec spec;

  if (os8ParseFilespec(fname, &spec, OS8_M_NONAME) == 0) {
    fprintf(stderr, "dir: syntax error in file spec \"%s\"\n", fname);
    return;
  }

  if (os8UnitValid(data, unit)) {
    unsigned int dirblk = OS8_DSSTART;

    do {
      uint16_t i, entrysz, entries, extra, off = OS8_DH_SIZE;

      if (os8ReadBlock(mount, unit, dirblk, NULL) == 0)
        return;

      entrysz = OS8_DI_SIZE + (-os8SXT(le16toh(data->buf[OS8_DH_EXTRA])));
      entries = os8Neg(le16toh(data->buf[OS8_DH_ENTRIES]));
      extra = os8Neg(le16toh(data->buf[OS8_DH_EXTRA]));

      for (i = 0; i < entries; i++) {
        char temp1[16], temp2[16];

        if (os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != 0) {
          if ((spec.flags & OS8_WC_NAME) == 0)
            if ((os8Word(le16toh(data->buf[off + OS8_DI_FNAME1])) != spec.name[0]) ||
                (os8Word(le16toh(data->buf[off + OS8_DI_FNAME2])) != spec.name[1]) ||
                (os8Word(le16toh(data->buf[off + OS8_DI_FNAME3])) != spec.name[2])) {
              off += entrysz;
              continue;
            }

          if ((spec.flags & OS8_WC_EXT) == 0)
            if (os8Word(le16toh(data->buf[off + OS8_DI_EXT])) != spec.ext) {
              off += entrysz;
              continue;
            }

          if (SWISSET('f')) {
            uint16_t length, dateval = 0;
            
            length = os8Neg(le16toh(data->buf[off + extra + OS8_DI_LENGTH]));
            if (extra)
              dateval = os8Word(le16toh(data->buf[off + OS8_DI_DATE]));

            printf("%s  %4hu  %s\n",
                   os8FileName(mount, off, temp1), length,
                   os8Date(dateval, temp2));
          } else printf("%s\n", os8FileName(mount, off, temp1));
          off += entrysz;
        } else off += OS8_ED_SIZE;
      }

      dirblk = os8Word(le16toh(data->buf[OS8_DH_NEXT]));
    } while (dirblk != 0);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %rbx
leaq 0x1e(%rsp), %rsi
pushq $0x2
popq %rdx
movq %r14, %rdi
callq 0xc779
testl %eax, %eax
je 0xe2c7
leaq 0x48(%rbx), %rdi
movzbl %bpl, %esi
movl %esi, 0x14(%rsp)
callq 0xd345
testl %eax, %eax
je 0xe2b8
movb 0x1e(%rsp), %bpl
movzwl 0x20(%rsp), %r13d
movzwl 0x22(%rsp), %eax
movw %ax, 0x10(%rsp)
movzwl 0x24(%rsp), %eax
movw %ax, 0xc(%rsp)
pushq $0x1
popq %rdx
movzwl 0x26(%rsp), %eax
movw %ax, 0x12(%rsp)
movb %bpl, 0xb(%rsp)
movw %r13w, 0xe(%rsp)
movq %rbx, 0x30(%rsp)
movq %rbx, %rdi
movl 0x14(%rsp), %esi
xorl %ecx, %ecx
callq 0xc5d7
testl %eax, %eax
je 0xe2b8
movzwl 0x64(%rbx), %esi
movl %esi, %eax
movl $0xfff, %edx            # imm = 0xFFF
andl %edx, %eax
movl %esi, %ecx
shll $0x4, %ecx
movswl %cx, %ecx
sarl $0xf, %ecx
andl $0xfffff000, %ecx       # imm = 0xFFFFF000
orl %eax, %ecx
pushq $0x5
popq %r12
subl %ecx, %r12d
movzwl 0x5c(%rbx), %eax
xorl %r14d, %r14d
subw %ax, %r14w
andl %edx, %r14d
negl %esi
andl %edx, %esi
movl %esi, 0x18(%rsp)
movl %esi, %eax
addl $0x4, %eax
movq %rax, 0x38(%rsp)
movw $0x5, %r15w
movw $0xfff, %di             # imm = 0xFFF
subw $0x1, %r14w
jb 0xe2a8
movzwl %r15w, %esi
movzwl 0x5c(%rbx,%rsi,2), %edx
andw %di, %dx
je 0xe219
movl %esi, %eax
testb $0x1, %bpl
jne 0xe1b5
movl %r12d, %ecx
cmpw %r13w, %dx
jne 0xe29a
movzwl 0x5e(%rbx,%rax,2), %edx
andl $0xfff, %edx            # imm = 0xFFF
movl %r12d, %ecx
cmpw 0x10(%rsp), %dx
jne 0xe29a
movzwl 0x60(%rbx,%rax,2), %edx
andl $0xfff, %edx            # imm = 0xFFF
movl %r12d, %ecx
cmpw 0xc(%rsp), %dx
jne 0xe29a
testb $0x2, %bpl
jne 0xe1d4
movzwl 0x62(%rbx,%rax,2), %edx
andl $0xfff, %edx            # imm = 0xFFF
movl %r12d, %ecx
cmpw 0x12(%rsp), %dx
jne 0xe29a
leaq 0x9dfd(%rip), %rcx      # 0x17fd8
testb $0x20, (%rcx)
jne 0xe21f
movq %rbx, %rdi
movl %ebp, %ebx
movl %r12d, %ebp
movl %r13d, %r12d
leaq 0x40(%rsp), %r13
movq %r13, %rdx
callq 0xe68d
movq %r13, %rdi
movl %r12d, %r13d
movl %ebp, %r12d
movl %ebx, %ebp
movq 0x30(%rsp), %rbx
callq 0x30e0
movw $0xfff, %di             # imm = 0xFFF
movl %r12d, %ecx
jmp 0xe29a
movw $0x2, %cx
jmp 0xe29a
xorl %r13d, %r13d
movl $0x0, %ebp
cmpw $0x0, 0x18(%rsp)
je 0xe23a
movzwl 0x64(%rbx,%rax,2), %ebp
andl $0xfff, %ebp            # imm = 0xFFF
movq 0x38(%rsp), %rax
addl %esi, %eax
subw 0x5c(%rbx,%rax,2), %r13w
andl $0xfff, %r13d           # imm = 0xFFF
movq %rbx, %rdi
leaq 0x40(%rsp), %rdx
callq 0xe68d
movzwl %r13w, %r13d
movzwl %bp, %edi
leaq 0x50(%rsp), %rbp
movq %rbp, %rsi
callq 0xe725
leaq 0x3974(%rip), %rdi      # 0x11bea
leaq 0x40(%rsp), %rsi
movl %r13d, %edx
movq %rbp, %rcx
xorl %eax, %eax
callq 0x3160
movl %r12d, %ecx
movb 0xb(%rsp), %bpl
movzwl 0xe(%rsp), %r13d
movw $0xfff, %di             # imm = 0xFFF
movswl %cx, %eax
addl %r15d, %eax
movl %eax, %r15d
jmp 0xe151
movzwl 0x60(%rbx), %edx
andl $0xfff, %edx            # imm = 0xFFF
jne 0xe0eb
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8d2a(%rip), %rax      # 0x16ff8
movq (%rax), %rdi
leaq 0x2aaa(%rip), %rsi      # 0x10d82
movq %r14, %rdx
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x31e0